
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>NDK · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="系统编译剪裁.html" />
    
    
    <link rel="prev" href="ccpp.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../doc/常用网站.html">
            
                <a href="../doc/常用网站.html">
            
                    
                    常用网站
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../常用软件/常用软件和框架.html">
            
                <a href="../常用软件/常用软件和框架.html">
            
                    
                    常用软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../doc/开发规范.html">
            
                <a href="../doc/开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../doc/开源软件.html">
            
                <a href="../doc/开源软件.html">
            
                    
                    开源软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../doc/Android常用代码.html">
            
                <a href="../doc/Android常用代码.html">
            
                    
                    Android常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../源码阅读/源码阅读配置.html">
            
                <a href="../源码阅读/源码阅读配置.html">
            
                    
                    源码阅读
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../源码阅读/其他框架源码.html">
            
                <a href="../源码阅读/其他框架源码.html">
            
                    
                    其他框架源码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../产品经理/产品经理.html">
            
                <a href="../产品经理/产品经理.html">
            
                    
                    产品经理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../设计模式/模式详解.html">
            
                <a href="../设计模式/模式详解.html">
            
                    
                    模式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../设计模式/mvc等.html">
            
                <a href="../设计模式/mvc等.html">
            
                    
                    mvc等
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    基本算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    常用数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../常用算法/算法术语.html">
            
                <a href="../常用算法/算法术语.html">
            
                    
                    算法术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../常用算法/排序算法.html">
            
                <a href="../常用算法/排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../常用算法/查找算法.html">
            
                <a href="../常用算法/查找算法.html">
            
                    
                    查找算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../常用算法/大数相加.html">
            
                <a href="../常用算法/大数相加.html">
            
                    
                    大数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../常用算法/集合的所有子集.html">
            
                <a href="../常用算法/集合的所有子集.html">
            
                    
                    获得集合的所有子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../常用算法/扫描线种子填充算法.html">
            
                <a href="../常用算法/扫描线种子填充算法.html">
            
                    
                    扫描线种子填充算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../常用算法/其他算法.html">
            
                <a href="../常用算法/其他算法.html">
            
                    
                    其他算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    Java部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    原码补码反码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../java基础/java常用代码.html">
            
                <a href="../java基础/java常用代码.html">
            
                    
                    java常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../java基础/JVM详解.html">
            
                <a href="../java基础/JVM详解.html">
            
                    
                    JVM详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../java基础/类加载机制.html">
            
                <a href="../java基础/类加载机制.html">
            
                    
                    类加载机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../java基础/内存模型.html">
            
                <a href="../java基础/内存模型.html">
            
                    
                    内存模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../java基础/GC机制.html">
            
                <a href="../java基础/GC机制.html">
            
                    
                    GC机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../java基础/对象内存布局.html">
            
                <a href="../java基础/对象内存布局.html">
            
                    
                    对象内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../java基础/继承多态.html">
            
                <a href="../java基础/继承多态.html">
            
                    
                    继承和多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../java基础/相等判断.html">
            
                <a href="../java基础/相等判断.html">
            
                    
                    相等判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../java基础/Java容器类.html">
            
                <a href="../java基础/Java容器类.html">
            
                    
                    Java容器类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../java基础/Java枚举.html">
            
                <a href="../java基础/Java枚举.html">
            
                    
                    Java枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../java基础/自定义异常.html">
            
                <a href="../java基础/自定义异常.html">
            
                    
                    自定义异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../java基础/深度拷贝.html">
            
                <a href="../java基础/深度拷贝.html">
            
                    
                    深度拷贝
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../java基础/泛型详解.html">
            
                <a href="../java基础/泛型详解.html">
            
                    
                    泛型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../java基础/线程详解.html">
            
                <a href="../java基础/线程详解.html">
            
                    
                    线程详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../java基础/java注解.html">
            
                <a href="../java基础/java注解.html">
            
                    
                    注解详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../java基础/数据解析.html">
            
                <a href="../java基础/数据解析.html">
            
                    
                    数据解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../java基础/java8新特性.html">
            
                <a href="../java基础/java8新特性.html">
            
                    
                    Java8新特性
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../android基础/基础控件使用.html">
            
                <a href="../android基础/基础控件使用.html">
            
                    
                    基础控件使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android零散知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../android基础/android坐标体系.html">
            
                <a href="../android基础/android坐标体系.html">
            
                    
                    Android坐标体系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../android基础/APP的启动流程.html">
            
                <a href="../android基础/APP的启动流程.html">
            
                    
                    APP启动流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../android基础/View加载流程.html">
            
                <a href="../android基础/View加载流程.html">
            
                    
                    View加载流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../android基础/事件分发机制.html">
            
                <a href="../android基础/事件分发机制.html">
            
                    
                    事件分发机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../android基础/控件绘制流程.html">
            
                <a href="../android基础/控件绘制流程.html">
            
                    
                    控件绘制流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="../android基础/常用shape.html">
            
                <a href="../android基础/常用shape.html">
            
                    
                    常用shape
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.9" data-path="../android基础/进程通信.html">
            
                <a href="../android基础/进程通信.html">
            
                    
                    进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.10" data-path="../通信方式/通信方式详解.html">
            
                <a href="../通信方式/通信方式详解.html">
            
                    
                    通信方式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.11" data-path="../android基础/Binder详解.html">
            
                <a href="../android基础/Binder详解.html">
            
                    
                    Binder详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.12" data-path="../android基础/Handler详解.html">
            
                <a href="../android基础/Handler详解.html">
            
                    
                    Handle详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.13" data-path="../android基础/Fragment详解.html">
            
                <a href="../android基础/Fragment详解.html">
            
                    
                    Fragment详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.14" data-path="../android基础/Activity详解.html">
            
                <a href="../android基础/Activity详解.html">
            
                    
                    Activity详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.15" data-path="../android基础/BroadcastReceiver.html">
            
                <a href="../android基础/BroadcastReceiver.html">
            
                    
                    BroadcastReceiver详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.16" data-path="../android基础/Service服务.html">
            
                <a href="../android基础/Service服务.html">
            
                    
                    Service详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.17" data-path="../android基础/动画详解.html">
            
                <a href="../android基础/动画详解.html">
            
                    
                    动画详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.18" data-path="../android基础/屏幕刷新机制.html">
            
                <a href="../android基础/屏幕刷新机制.html">
            
                    
                    屏幕刷新机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.19" data-path="../android基础/屏幕适配.html">
            
                <a href="../android基础/屏幕适配.html">
            
                    
                    屏幕适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.20" data-path="../android基础/图片加载详解.html">
            
                <a href="../android基础/图片加载详解.html">
            
                    
                    图片加载详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.21" data-path="../android基础/WebView详解.html">
            
                <a href="../android基础/WebView详解.html">
            
                    
                    WebView详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.22" data-path="../android基础/沉浸式.html">
            
                <a href="../android基础/沉浸式.html">
            
                    
                    沉浸式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.23" data-path="../android基础/相机模块.html">
            
                <a href="../android基础/相机模块.html">
            
                    
                    相机模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.24" data-path="../android基础/地图模块.html">
            
                <a href="../android基础/地图模块.html">
            
                    
                    地图模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.25" data-path="../android基础/Androidstudio插件开发.html">
            
                <a href="../android基础/Androidstudio插件开发.html">
            
                    
                    Androidstudio插件开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.26" data-path="../android基础/Apk插件化开发.html">
            
                <a href="../android基础/Apk插件化开发.html">
            
                    
                    Apk插件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.27" data-path="../android基础/App组件化开发.html">
            
                <a href="../android基础/App组件化开发.html">
            
                    
                    App组件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.28" data-path="../android基础/sdk开发.html">
            
                <a href="../android基础/sdk开发.html">
            
                    
                    sdk开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.29" data-path="../android基础/APP优化.html">
            
                <a href="../android基础/APP优化.html">
            
                    
                    APP优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.30" data-path="../android基础/项目参数配置.html">
            
                <a href="../android基础/项目参数配置.html">
            
                    
                    项目参数配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.31" data-path="../android基础/App发布.html">
            
                <a href="../android基础/App发布.html">
            
                    
                    App发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.32" data-path="../android基础/Android外挂.html">
            
                <a href="../android基础/Android外挂.html">
            
                    
                    Android外挂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.33" data-path="../android基础/Android字节码插桩.html">
            
                <a href="../android基础/Android字节码插桩.html">
            
                    
                    Android字节码插桩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.34" data-path="../android基础/智能家居.html">
            
                <a href="../android基础/智能家居.html">
            
                    
                    智能家居
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../python/python爬虫.html">
            
                <a href="../python/python爬虫.html">
            
                    
                    python爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../gradle/Groovy.html">
            
                <a href="../gradle/Groovy.html">
            
                    
                    Groovy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../kotlin/kotlin部分.html">
            
                <a href="../kotlin/kotlin部分.html">
            
                    
                    kotlin部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../flutter/flutter部分.html">
            
                <a href="../flutter/flutter部分.html">
            
                    
                    flutter部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="ccpp.html">
            
                <a href="ccpp.html">
            
                    
                    native部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="Linux.html">
            
                <a href="Linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="ccpp.html">
            
                <a href="ccpp.html">
            
                    
                    cCpp
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.17.3" data-path="NDK.html">
            
                <a href="NDK.html">
            
                    
                    NDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="系统编译剪裁.html">
            
                <a href="系统编译剪裁.html">
            
                    
                    系统编译剪裁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="音视频.html">
            
                <a href="音视频.html">
            
                    
                    音视频
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="音视频第三方库.html">
            
                <a href="音视频第三方库.html">
            
                    
                    音视频第三方库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.7" data-path="相关代码.html">
            
                <a href="相关代码.html">
            
                    
                    相关代码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../server/服务器部分.html">
            
                <a href="../server/服务器部分.html">
            
                    
                    服务器部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../webDev/web部分.html">
            
                <a href="../webDev/web部分.html">
            
                    
                    web部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../人工智能/人工智能相关概念.html">
            
                <a href="../人工智能/人工智能相关概念.html">
            
                    
                    人工智能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../面试真题/极飞.html">
            
                <a href="../面试真题/极飞.html">
            
                    
                    面试真题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >NDK</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#ndk-&#x4EA4;&#x53C9;&#x7F16;&#x8BD1;"><b>1. </b>NDK &#x4EA4;&#x53C9;&#x7F16;&#x8BD1;</a></li><ul><li><span class="title-icon "></span><a href="#&#x52A8;&#x6001;&#x5E93;"><b>1.1. </b>&#x52A8;&#x6001;&#x5E93;</a></li><li><span class="title-icon "></span><a href="#&#x9759;&#x6001;&#x5E93;"><b>1.2. </b>&#x9759;&#x6001;&#x5E93;</a></li><li><span class="title-icon "></span><a href="#window&#x4E0B;-mingw-&#x6A21;&#x62DF;-linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;"><b>1.3. </b>window&#x4E0B; MinGW &#x6A21;&#x62DF; linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;</a></li></ul><li><span class="title-icon "></span><a href="#&#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><b>2. </b>&#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;</a></li><ul><li><span class="title-icon "></span><a href="#build-&#x5E38;&#x7528;&#x547D;&#x4EE4;"><b>2.1. </b>build &#x5E38;&#x7528;&#x547D;&#x4EE4;</a></li><li><span class="title-icon "></span><a href="#androidmk-&#x6A21;&#x677F;"><b>2.2. </b>Android.mk &#x6A21;&#x677F;</a></li><li><span class="title-icon "></span><a href="#androidmk-&#x914D;&#x7F6E;&#x793A;&#x4F8B;"><b>2.3. </b>Android.mk &#x914D;&#x7F6E;&#x793A;&#x4F8B;</a></li><li><span class="title-icon "></span><a href="#androidmk-&#x90E8;&#x5206;&#x89E3;&#x91CA;"><b>2.4. </b>Android.mk &#x90E8;&#x5206;&#x89E3;&#x91CA;</a></li><ul><li><span class="title-icon "></span><a href="#localpath--call-my-dir"><b>2.4.1. </b>LOCAL_PATH := $(call my-dir)</a></li><li><span class="title-icon "></span><a href="#include-clearvars"><b>2.4.2. </b>include $(CLEAR_VARS)</a></li><li><span class="title-icon "></span><a href="#localmodule--hello-jni"><b>2.4.3. </b>LOCAL_MODULE := hello-jni</a></li><li><span class="title-icon "></span><a href="#localsrcfiles--hello-jnic"><b>2.4.4. </b>LOCAL_SRC_FILES := hello-jni.c</a></li></ul><li><span class="title-icon "></span><a href="#&#x53D8;&#x91CF;&#x548C;&#x5B8F;"><b>2.5. </b>&#x53D8;&#x91CF;&#x548C;&#x5B8F;</a></li><ul><li><span class="title-icon "></span><a href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;"><b>2.5.1. </b>&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;</a></li><li><span class="title-icon "></span><a href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;"><b>2.5.2. </b>&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5176;&#x4ED6;"><b>2.6. </b>&#x5176;&#x4ED6;</a></li><li><span class="title-icon "></span><a href="#applicationmk&#x6A21;&#x677F;"><b>2.7. </b>Application.mk&#x6A21;&#x677F;</a></li><li><span class="title-icon "></span><a href="#applicationmk-&#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;"><b>2.8. </b>Application.mk &#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;</a></li><li><span class="title-icon "></span><a href="#applicationmk-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><b>2.9. </b>Application.mk &#x7B80;&#x5355;&#x793A;&#x4F8B;</a></li><li><span class="title-icon "></span><a href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;_1"><b>2.10. </b>&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;</a></li></ul><li><span class="title-icon "></span><a href="#cmake-&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><b>3. </b>cmake &#x7F16;&#x8BD1;&#x65B9;&#x5F0F;</a></li><ul><li><span class="title-icon "></span><a href="#cmake"><b>3.1. </b>CMake</a></li><li><span class="title-icon "></span><a href="#lldb"><b>3.2. </b>LLDB</a></li><li><span class="title-icon "></span><a href="#androidstudio22-&#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;"><b>3.3. </b>androidstudio2.2+ &#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;</a></li><li><span class="title-icon "></span><a href="#buildgradle-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><b>3.4. </b>build.gradle &#x90E8;&#x5206;&#x914D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#cmakeliststxt-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><b>3.5. </b>CMakeLists.txt &#x90E8;&#x5206;&#x914D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#cmakeliststxt-&#x8BF4;&#x660E;"><b>3.6. </b>CMakeLists.txt &#x8BF4;&#x660E;</a></li><li><span class="title-icon "></span><a href="#&#x5176;&#x4ED6;&#x914D;&#x7F6E;"><b>3.7. </b>&#x5176;&#x4ED6;&#x914D;&#x7F6E;</a></li></ul><li><span class="title-icon "></span><a href="#jni"><b>4. </b>jni</a></li><ul><li><span class="title-icon "></span><a href="#jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><b>4.1. </b>JNI &#x4F7F;&#x7528;&#x573A;&#x666F;</a></li><li><span class="title-icon "></span><a href="#jni&#x8BED;&#x6CD5;"><b>4.2. </b>JNI&#x8BED;&#x6CD5;</a></li><ul><li><span class="title-icon "></span><a href="#jnienv"><b>4.2.1. </b>JNIEnv</a></li></ul><li><span class="title-icon "></span><a href="#jni-&#x52A8;&#x6001;&#x6CE8;&#x518C;-&#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;"><b>4.3. </b>JNI &#x52A8;&#x6001;&#x6CE8;&#x518C; &#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;</a></li><li><span class="title-icon "></span><a href="#jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><b>4.4. </b>JNI&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x4E32;"><b>4.5. </b>&#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#jni&#x7B7E;&#x540D;"><b>4.6. </b>JNI&#x7B7E;&#x540D;</a></li><ul><li><span class="title-icon "></span><a href="#&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><b>4.6.1. </b>&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;</a></li><li><span class="title-icon "></span><a href="#&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><b>4.6.2. </b>&#x7B7E;&#x540D;&#x8BE6;&#x89E3;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5F15;&#x7528;&#x7C7B;&#x578B;"><b>4.7. </b>&#x5F15;&#x7528;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><b>4.8. </b>Java &#x548C; C &#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;</a></li><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;&#x51FD;&#x6570;"><b>4.9. </b>&#x5E38;&#x7528;&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#jnionload"><b>4.9.1. </b>JNI_OnLoad(...)</a></li></ul><li><span class="title-icon "></span><a href="#&#x6253;&#x5370;&#x65E5;&#x5FD7;"><b>4.10. </b>&#x6253;&#x5370;&#x65E5;&#x5FD7;</a></li><li><span class="title-icon "></span><a href="#&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><b>4.11. </b>&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;</a></li><li><span class="title-icon "></span><a href="#&#x7F13;&#x5B58;&#x7B56;&#x7565;"><b>4.12. </b>&#x7F13;&#x5B58;&#x7B56;&#x7565;</a></li><li><span class="title-icon "></span><a href="#java&#x8C03;&#x7528;native"><b>4.13. </b>java&#x8C03;&#x7528;native</a></li><li><span class="title-icon "></span><a href="#native-&#x8C03;&#x7528;-java"><b>4.14. </b>native &#x8C03;&#x7528; java</a></li><ul><li><span class="title-icon "></span><a href="#c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><b>4.14.1. </b>C++&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><b>4.14.2. </b>C++&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</a></li></ul><li><span class="title-icon "></span><a href="#posix&#x7EBF;&#x7A0B;"><b>4.15. </b>POSIX&#x7EBF;&#x7A0B;</a></li><ul><li><span class="title-icon "></span><a href="#posix-&#x4F7F;&#x7528;"><b>4.15.1. </b>POSIX &#x4F7F;&#x7528;</a></li><li><span class="title-icon "></span><a href="#posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><b>4.15.2. </b>POSIX &#x5E38;&#x7528;&#x65B9;&#x6CD5;</a></li></ul><li><span class="title-icon "></span><a href="#java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><b>4.16. </b>java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;</a></li><li><span class="title-icon "></span><a href="#&#x5176;&#x4ED6;_1"><b>4.17. </b>&#x5176;&#x4ED6;</a></li><li><span class="title-icon "></span><a href="#jni-demo"><b>4.18. </b>jni Demo</a></li><li><span class="title-icon "></span><a href="#jni&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;"><b>4.19. </b>JNI&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;</a></li><li><span class="title-icon "></span><a href="#posix-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><b>4.20. </b>POSIX &#x7B80;&#x5355;&#x793A;&#x4F8B;</a></li><li><span class="title-icon "></span><a href="#tcp-socket-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><b>4.21. </b>TCP socket &#x7B80;&#x5355;&#x793A;&#x4F8B;</a></li></ul></ul></div><a href="#ndk-&#x4EA4;&#x53C9;&#x7F16;&#x8BD1;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="ndk-&#x4EA4;&#x53C9;&#x7F16;&#x8BD1;"><a name="ndk-&#x4EA4;&#x53C9;&#x7F16;&#x8BD1;" class="anchor-navigation-ex-anchor" href="#ndk-&#x4EA4;&#x53C9;&#x7F16;&#x8BD1;"><i class="fa fa-link" aria-hidden="true"></i></a>1. NDK &#x4EA4;&#x53C9;&#x7F16;&#x8BD1;</h1>
<p>&#x5C31;&#x662F;&#x5728;&#x4E00;&#x4E2A;&#x5E73;&#x53F0;&#x4E0A;&#x751F;&#x6210;&#x53E6;&#x4E00;&#x4E2A;&#x5E73;&#x53F0;&#x4E0A;&#x7684;&#x53EF;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x3002; &#x4F8B;&#x5982;&#x5728;window&#x5E73;&#x53F0;&#x4E0B;&#x7F16;&#x8BD1;&#x751F;&#x6210;Apk &#x3002;</p>
<h2 id="&#x52A8;&#x6001;&#x5E93;"><a name="&#x52A8;&#x6001;&#x5E93;" class="anchor-navigation-ex-anchor" href="#&#x52A8;&#x6001;&#x5E93;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x52A8;&#x6001;&#x5E93;</h2>
<pre><code class="lang-text">.so  &#x3001; .dll
</code></pre>
<h2 id="&#x9759;&#x6001;&#x5E93;"><a name="&#x9759;&#x6001;&#x5E93;" class="anchor-navigation-ex-anchor" href="#&#x9759;&#x6001;&#x5E93;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x9759;&#x6001;&#x5E93;</h2>
<pre><code class="lang-text">.a  &#x3001; .lib  
&#x5C06;&#x6240;&#x4F9D;&#x8D56;&#x7684;&#x6587;&#x4EF6;&#x90FD;&#x7F16;&#x8BD1;&#x5230;&#x540C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x3002;&#x4F53;&#x79EF;&#x5927;&#x3002;
</code></pre>
<h2 id="window&#x4E0B;-mingw-&#x6A21;&#x62DF;-linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;"><a name="window&#x4E0B;-mingw-&#x6A21;&#x62DF;-linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;" class="anchor-navigation-ex-anchor" href="#window&#x4E0B;-mingw-&#x6A21;&#x62DF;-linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. window&#x4E0B; MinGW &#x6A21;&#x62DF; linux&#x7F16;&#x8BD1;&#x73AF;&#x5883;</h2>
<p><a href="http://www.mingw.org/" target="_blank">MinGW</a>(Minimalist GNUfor Windows)  &#x53EF;&#x4EE5;&#x5728;window&#x4E0B;&#x6A21;&#x62DF;linux&#x73AF;&#x5883;&#x3002;&#x5F53;&#x4F60;&#x6CA1;&#x6709;linux&#x73AF;&#x5883;&#x6216;&#x8005;&#x5728;linux&#x4E0B;&#x9047;&#x5230;&#x5947;&#x8469;&#x95EE;&#x9898;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x8FD9;&#x4E2A;&#x66FF;&#x4EE3;&#x4E00;&#x4E0B;&#x3002;</p>
<pre><code class="lang-text">1&#x3001;&#x5C06;&#x9ED8;&#x8BA4;&#x7684;&#x90A3;&#x4E9B;&#x7F16;&#x8BD1;&#x5668;&#x7B49;&#x90FD;&#x5B89;&#x88C5;&#x597D;&#x3002;
2&#x3001;&#x7136;&#x540E;&#x70B9;&#x51FB;  xxx\msys\1.0\msys.bat &#x5373;&#x53EF;&#x4F7F;&#x7528;
</code></pre>
<h1 id="&#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><a name="&#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x4F20;&#x7EDF;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;</h1>
<h2 id="build-&#x5E38;&#x7528;&#x547D;&#x4EE4;"><a name="build-&#x5E38;&#x7528;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#build-&#x5E38;&#x7528;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. build &#x5E38;&#x7528;&#x547D;&#x4EE4;</h2>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>ndk-build</td>
<td>&#x7F16;&#x8BD1;</td>
</tr>
<tr>
<td>ndk-build V=1</td>
<td>&#x7F16;&#x8BD1;&#x5E76;&#x6253;&#x5370;&#x51FA;&#x5B83;&#x6240;&#x6267;&#x884C;&#x7684;&#x8BE6;&#x7EC6;&#x7F16;&#x8BD1;&#x547D;&#x4EE4;</td>
</tr>
<tr>
<td>ndk-build NDK_DEBUG=1</td>
<td>&#x7F16;&#x8BD1;&#x4E3A;&#x8C03;&#x8BD5;&#x7248;&#x672C;</td>
</tr>
<tr>
<td>ndk-build NDK_DEBUG=0</td>
<td>&#x7F16;&#x8BD1;&#x4E3A; &#x6B63;&#x5F0F;&#x7248;&#x672C;</td>
</tr>
<tr>
<td>ndk-build NDK_OUT=./mydir</td>
<td>&#x6307;&#x5B9A;&#x7F16;&#x8BD1;&#x751F;&#x6210;&#x7684;&#x6587;&#x4EF6;&#x7684;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;</td>
</tr>
<tr>
<td>ndk-build -B</td>
<td>&#x5F3A;&#x5236;&#x91CD;&#x65B0;&#x7F16;&#x8BD1;&#x5DF2;&#x7ECF;&#x7F16;&#x8BD1;&#x5B8C;&#x6210;&#x7684;&#x4EE3;&#x7801;</td>
</tr>
<tr>
<td>ndk-build clean</td>
<td>&#x6E05;&#x9664;&#x6240;&#x6709;&#x7F16;&#x8BD1;&#x51FA;&#x6765;&#x7684;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x548C;&#x76EE;&#x6807;&#x6587;&#x4EF6;</td>
</tr>
</tbody>
</table>
<h2 id="androidmk-&#x6A21;&#x677F;"><a name="androidmk-&#x6A21;&#x677F;" class="anchor-navigation-ex-anchor" href="#androidmk-&#x6A21;&#x677F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. Android.mk &#x6A21;&#x677F;</h2>
<p>android_mk <a href="https://developer.android.google.cn/ndk/guides/android_mk.html#over" target="_blank"> &#x5B98;&#x65B9;&#x53C2;&#x8003;</a></p>
<h2 id="androidmk-&#x914D;&#x7F6E;&#x793A;&#x4F8B;"><a name="androidmk-&#x914D;&#x7F6E;&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#androidmk-&#x914D;&#x7F6E;&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. Android.mk &#x914D;&#x7F6E;&#x793A;&#x4F8B;</h2>
<pre><code class="lang-text">LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libffmpeg  \
    $(LOCAL_PATH)/hardCodec

LOCAL_MODULE := libhiesproto
ALL_DEFAULT_INSTALLED_MODULES += $(LOCAL_MODULE)
LOCAL_STATIC_LIBRARIES := libyuv2rgb_neon
LOCAL_SRC_FILES += Hies_proto.c \
    comm_utils.c \
    mbuffer/HiMbuffer.c

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libh265decoder
LOCAL_SRC_FILES := hardCodec/H265/lib/libHW_H265dec_Andr.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_CFLAGS := -D__STDC_CONSTANT_MACROS -DHI_OS_ANDROID -DHI_MEDIA_CODEC_DECODING

WITH_ANDROID_VECTOR := true
include $(LOCAL_PATH)/../utils.mk
LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/../libffmpeg \
    $(LOCAL_PATH)/../arm_neon \
    $(LOCAL_PATH)/../jni \

LOCAL_SRC_FILES := \
    mediaplayer.cpp \
    nativeWindow.cpp \
    mbuffer/HiMbuffer.c \

RTSP_PROTO_INC := \
    $(LOCAL_PATH)/hardCodec/protocol/HiRtspClient \
    $(LOCAL_PATH)/hardCodec/protocol/HiRtspClient/rtspclient/include \
    $(LOCAL_PATH)/hardCodec/protocol/HiRtspClient/rtspclient/src

RTSP_PROTO_SRC := $(wildcard $(LOCAL_PATH)/hardCodec/protocol/HiRtspClient/rtspclient/src/*.c)

LOCAL_C_INCLUDES += $(RTSP_PROTO_INC)
LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(RTSP_PROTO_SRC))
LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES := libffmpeg libmpp libvpu
LOCAL_STATIC_LIBRARIES :=libHWAHStreaming libyuv2rgb_neon libhiesproto libh265decoder

LOCAL_LDLIBS += -llog -lz -lm -ldl
LOCAL_MODULE := libahplayer
ALL_DEFAULT_INSTALLED_MODULES += $(LOCAL_MODULE)
include $(BUILD_STATIC_LIBRARY)
</code></pre>
<h2 id="androidmk-&#x90E8;&#x5206;&#x89E3;&#x91CA;"><a name="androidmk-&#x90E8;&#x5206;&#x89E3;&#x91CA;" class="anchor-navigation-ex-anchor" href="#androidmk-&#x90E8;&#x5206;&#x89E3;&#x91CA;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. Android.mk &#x90E8;&#x5206;&#x89E3;&#x91CA;</h2>
<h3 id="localpath--call-my-dir"><a name="localpath--call-my-dir" class="anchor-navigation-ex-anchor" href="#localpath--call-my-dir"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.1. LOCAL_PATH := $(call my-dir)</h3>
<pre><code class="lang-text">&#x8868;&#x793A;&#x6E90;&#x6587;&#x4EF6;&#x5728;&#x5F00;&#x53D1;&#x6811;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#x3002;
&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x63D0;&#x4F9B;&#x7684;&#x5B8F;&#x51FD;&#x6570; my-dir &#x5C06;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#xFF08;&#x5373;Android.mk&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x76EE;&#x5F55;&#xFF09;&#x7684;&#x8DEF;&#x5F84;&#x3002;
</code></pre>
<h3 id="include-clearvars"><a name="include-clearvars" class="anchor-navigation-ex-anchor" href="#include-clearvars"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.2. include $(CLEAR_VARS)</h3>
<pre><code class="lang-text">CLEAR_VARS &#x53D8;&#x91CF;
&#x5176;&#x503C;&#x7531;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x63D0;&#x4F9B;&#x3002;&#x6307;&#x5411;&#x7279;&#x6B8A; GNU Makefile&#xFF0C;&#x53EF;&#x4E3A;&#x60A8;&#x6E05;&#x9664;&#x8BB8;&#x591A; LOCAL_XXX &#x53D8;&#x91CF;&#xFF0C;
&#x4F8B;&#x5982; LOCAL_MODULE&#x3001;LOCAL_SRC_FILES &#x548C; LOCAL_STATIC_LIBRARIES&#x3002;
&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x5B83;&#x4E0D;&#x4F1A;&#x6E05;&#x9664; LOCAL_PATH&#x3002;&#x6B64;&#x53D8;&#x91CF;&#x5FC5;&#x987B;&#x4FDD;&#x7559;&#x5176;&#x503C;&#xFF0C;&#x56E0;&#x4E3A;&#x7CFB;&#x7EDF;&#x5728;&#x5355;&#x4E00; GNU Make &#x6267;&#x884C;&#x73AF;&#x5883;&#xFF08;&#x5176;&#x4E2D;&#x6240;&#x6709;&#x53D8;&#x91CF;&#x90FD;&#x662F;&#x5168;&#x5C40;&#x7684;&#xFF09;&#x4E2D;&#x89E3;&#x6790;&#x6240;&#x6709;&#x6784;&#x5EFA;&#x63A7;&#x5236;&#x6587;&#x4EF6;&#x3002;
&#x5728;&#x63CF;&#x8FF0;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x4E4B;&#x524D;&#xFF0C;&#x5FC5;&#x987B;&#x58F0;&#x660E;&#xFF08;&#x91CD;&#x65B0;&#x58F0;&#x660E;&#xFF09;&#x6B64;&#x53D8;&#x91CF;&#x3002;
</code></pre>
<h3 id="localmodule--hello-jni"><a name="localmodule--hello-jni" class="anchor-navigation-ex-anchor" href="#localmodule--hello-jni"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.3. LOCAL_MODULE := hello-jni</h3>
<pre><code class="lang-text">LOCAL_MODULE &#x53D8;&#x91CF;
&#x5C06;&#x5B58;&#x50A8;&#x60A8;&#x8981;&#x6784;&#x5EFA;&#x7684;&#x6A21;&#x5757;&#x7684;&#x540D;&#x79F0;&#x3002;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x540D;&#x79F0;&#x5FC5;&#x987B;&#x552F;&#x4E00;&#xFF0C;&#x4E14;&#x4E0D;&#x542B;&#x4EFB;&#x4F55;&#x7A7A;&#x683C;&#x3002;
</code></pre>
<h3 id="localsrcfiles--hello-jnic"><a name="localsrcfiles--hello-jnic" class="anchor-navigation-ex-anchor" href="#localsrcfiles--hello-jnic"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.4. LOCAL_SRC_FILES := hello-jni.c</h3>
<pre><code class="lang-text">&#x6700;&#x540E;&#x4E00;&#x884C;&#x5E2E;&#x52A9;&#x7CFB;&#x7EDF;&#x5C06;&#x6240;&#x6709;&#x5185;&#x5BB9;&#x8FDE;&#x63A5;&#x5230;&#x4E00;&#x8D77;&#x3002;
include $(BUILD_SHARED_LIBRARY)

BUILD_SHARED_LIBRARY &#x53D8;&#x91CF;
&#x6307;&#x5411; GNU Makefile &#x811A;&#x672C;&#xFF0C;&#x7528;&#x4E8E;&#x6536;&#x96C6;&#x60A8;&#x81EA;&#x6700;&#x8FD1; include &#x540E;&#x5728; LOCAL_XXX &#x53D8;&#x91CF;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x6240;&#x6709;&#x4FE1;&#x606F;&#x3002;
</code></pre>
<h2 id="&#x53D8;&#x91CF;&#x548C;&#x5B8F;"><a name="&#x53D8;&#x91CF;&#x548C;&#x5B8F;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;&#x548C;&#x5B8F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5. &#x53D8;&#x91CF;&#x548C;&#x5B8F;</h2>
<pre><code class="lang-text">&#x7CFB;&#x7EDF;&#x63D0;&#x4F9B;&#x8BB8;&#x591A;&#x53EF;&#x7528;&#x4E8E; Android.mk &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x53D8;&#x91CF;&#x3002;
&#x9664;&#x4E86;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#x4E4B;&#x5916;&#xFF0C;&#x60A8;&#x8FD8;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x81EA;&#x5DF1;&#x7684;&#x4EFB;&#x610F;&#x53D8;&#x91CF;&#x3002;
&#x4E3A;&#x4E86;&#x4FBF;&#x4E8E;&#x8FA8;&#x8BA4;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x5EFA;&#x8BAE;&#x5728;&#x540D;&#x79F0;&#x524D;&#x9644;&#x52A0; MY_&#x3002;
</code></pre>
<h3 id="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;"><a name="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5.1. &#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;</h3>
<table>
<thead>
<tr>
<th>NDK &#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;</th>
<th>&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td>CLEAR_VARS</td>
<td>&#x53D6;&#x6D88;&#x5B9A;&#x4E49;LOCAL_XXX &#x53D8;&#x91CF;&#x3002;</td>
</tr>
<tr>
<td>BUILD_SHARED_LIBRARY</td>
<td>&#x6784;&#x5EFA;&#x52A8;&#x6001;&#x5E93;</td>
</tr>
<tr>
<td>BUILD_STATIC_LIBRARY</td>
<td>&#x6784;&#x5EFA;&#x9759;&#x6001;&#x5E93;</td>
</tr>
<tr>
<td>PREBUILT_SHARED_LIBRARY</td>
<td>&#x5F15;&#x7528;&#x53E6;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x9884;&#x5EFA;&#x5E93;</td>
</tr>
<tr>
<td>PREBUILT_STATIC_LIBRARY</td>
<td></td>
</tr>
<tr>
<td>TARGET_ARCH</td>
<td>CPU &#x67B6;&#x6784;&#x7684;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td>TARGET_ARCH_ABI</td>
<td>&#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x4F5C;&#x4E3A;&#x591A;&#x4E2A;&#x76EE;&#x6807;&#x4E4B;&#x95F4;&#x7684;&#x5206;&#x9694;&#x7B26;</td>
</tr>
<tr>
<td>TARGET_PLATFORM</td>
<td>&#x4F5C;&#x4E3A;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x76EE;&#x6807;&#x7684; Android API &#x7EA7;&#x522B;&#x53F7;</td>
</tr>
<tr>
<td>TARGET_ABI</td>
<td></td>
</tr>
<tr>
<td>LOCAL_PATH</td>
<td>&#x6307;&#x5B9A;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>LOCAL_MODULE</td>
<td>&#x6A21;&#x5757;&#x7684;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td>LOCAL_MODULE_FILENAME</td>
<td>&#x5F3A;&#x5236;&#x6539;&#x53D8;.so&#x7684;&#x6587;&#x4EF6;&#x540D;</td>
</tr>
<tr>
<td>LOCAL_SRC_FILES</td>
<td>&#x6E90;&#x6587;&#x4EF6;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_CPP_EXTENSION</td>
<td>&#x4E3A; C++ &#x6E90;&#x6587;&#x4EF6;&#x6307;&#x660E; .cpp &#x4EE5;&#x5916;&#x7684;&#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;</td>
</tr>
<tr>
<td>LOCAL_CPP_FEATURES</td>
<td>&#x6307;&#x660E;&#x60A8;&#x7684;&#x4EE3;&#x7801;&#x4F9D;&#x8D56;&#x4E8E;&#x7279;&#x5B9A; C++ &#x529F;&#x80FD;</td>
</tr>
<tr>
<td>LOCAL_C_INCLUDES</td>
<td>&#x6307;&#x5B9A;&#x76F8;&#x5BF9;&#x4E8E; NDK root &#x76EE;&#x5F55;&#x7684;&#x8DEF;&#x5F84;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_CFLAGS</td>
<td>&#x8BBE;&#x7F6E;&#x5728;&#x6784;&#x5EFA; C &#x548C; C++ &#x6E90;&#x6587;&#x4EF6;&#x65F6;&#x8981;&#x4F20;&#x9012;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x6807;&#x5FD7;&#x3002;</td>
</tr>
<tr>
<td>LOCAL_CPPFLAGS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_STATIC_LIBRARIES</td>
<td>&#x5B58;&#x50A8;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x4F9D;&#x8D56;&#x7684;&#x9759;&#x6001;&#x5E93;&#x6A21;&#x5757;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_SHARED_LIBRARIES</td>
<td>&#x4F9D;&#x8D56;&#x7684;&#x5171;&#x4EAB;&#x5E93;&#x6A21;&#x5757;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_WHOLE_STATIC_LIBRARIES</td>
<td>&#x8868;&#x793A;&#x94FE;&#x63A5;&#x5668;&#x5E94;&#x5C06;&#x76F8;&#x5173;&#x7684;&#x5E93;&#x6A21;&#x5757;&#x89C6;&#x4E3A;&#x6574;&#x4E2A;&#x5B58;&#x6863;</td>
</tr>
<tr>
<td>LOCAL_LDLIBS</td>
<td>&#x5176;&#x4ED6;&#x94FE;&#x63A5;&#x5668;&#x6807;&#x5FD7;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_LDFLAGS</td>
<td>&#x5176;&#x4ED6;&#x94FE;&#x63A5;&#x5668;&#x6807;&#x5FD7;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>LOCAL_ALLOW_UNDEFINED_SYMBOLS</td>
<td>&#x6355;&#x83B7;&#x201C;&#x672A;&#x5B9A;&#x4E49;&#x7684;&#x7B26;&#x53F7;&#x201D;&#x9519;&#x8BEF;</td>
</tr>
<tr>
<td>LOCAL_ARM_MODE</td>
<td></td>
</tr>
<tr>
<td>LOCAL_ARM_NEON</td>
<td></td>
</tr>
<tr>
<td>LOCAL_DISABLE_NO_EXECUTE</td>
<td></td>
</tr>
<tr>
<td>LOCAL_DISABLE_RELRO</td>
<td></td>
</tr>
<tr>
<td>LOCAL_DISABLE_FORMAT_STRING_CHECKS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_EXPORT_CFLAGS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_EXPORT_CPPFLAGS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_EXPORT_C_INCLUDES</td>
<td></td>
</tr>
<tr>
<td>LOCAL_EXPORT_LDFLAGS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_EXPORT_LDLIBS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_SHORT_COMMANDS</td>
<td></td>
</tr>
<tr>
<td>LOCAL_THIN_ARCHIVE</td>
<td></td>
</tr>
<tr>
<td>LOCAL_FILTER_ASM</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;"><a name="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;" class="anchor-navigation-ex-anchor" href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5.2. &#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x51FD;&#x6570;&#x5B8F;</h3>
<table>
<thead>
<tr>
<th>NDK &#x63D0;&#x4F9B;&#x7684;&#x51FD;&#x6570;&#x5B8F;</th>
<th>&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td>my-dir</td>
<td>&#x8FD4;&#x56DE;&#x6700;&#x540E;&#x5305;&#x542B;&#x7684; makefile &#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x901A;&#x5E38;&#x662F;&#x5F53;&#x524D; Android.mk &#x7684;&#x76EE;&#x5F55;</td>
</tr>
<tr>
<td>all-subdir-makefiles</td>
<td>&#x8FD4;&#x56DE;&#x4F4D;&#x4E8E;&#x5F53;&#x524D; my-dir &#x8DEF;&#x5F84;&#x6240;&#x6709;&#x5B50;&#x76EE;&#x5F55;&#x4E2D;&#x7684; Android.mk &#x6587;&#x4EF6;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>this-makefile</td>
<td>&#x8FD4;&#x56DE;&#x5F53;&#x524D; makefile &#x7684;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>parent-makefile</td>
<td>&#x8FD4;&#x56DE;&#x5305;&#x542B;&#x6811;&#x4E2D;&#x7236; makefile &#x7684;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>grand-parent-makefile</td>
<td>&#x8FD4;&#x56DE;&#x5305;&#x542B;&#x6811;&#x4E2D;&#x7956;&#x7236; makefile &#x7684;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>import-module</td>
<td>&#x6309;&#x6A21;&#x5757;&#x7684;&#x540D;&#x79F0;&#x67E5;&#x627E;&#x548C;&#x5305;&#x542B;&#x6A21;&#x5757;&#x7684; Android.mk  </td>
</tr>
</tbody>
</table>
<h2 id="&#x5176;&#x4ED6;"><a name="&#x5176;&#x4ED6;" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;"><i class="fa fa-link" aria-hidden="true"></i></a>2.6. &#x5176;&#x4ED6;</h2>
<pre><code class="lang-text">if [ $? -eq 0 ]
$?&#x662F;shell&#x53D8;&#x91CF;,&#x8868;&#x793A;&quot;&#x6700;&#x540E;&#x4E00;&#x6B21;&#x6267;&#x884C;&#x547D;&#x4EE4;&quot;&#x7684;&#x9000;&#x51FA;&#x72B6;&#x6001;.0&#x4E3A;&#x6210;&#x529F;,&#x975E;0&#x4E3A;&#x5931;&#x8D25;.
</code></pre>
<h2 id="applicationmk&#x6A21;&#x677F;"><a name="applicationmk&#x6A21;&#x677F;" class="anchor-navigation-ex-anchor" href="#applicationmk&#x6A21;&#x677F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.7. Application.mk&#x6A21;&#x677F;</h2>
<p><a href="https://developer.android.google.cn/ndk/guides/application_mk.html" target="_blank">Application.mk&#x5B98;&#x65B9;&#x53C2;&#x8003;&#x8D44;&#x6599;</a></p>
<pre><code class="lang-text">Application.mk&#x4E0D;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;&#x5C31;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x5957;&#x81EA;&#x5DF1;&#x7684;&#x9ED8;&#x8BA4;&#x89C4;&#x5219;&#x3002;
&#x81EA;&#x5B9A;&#x4E49;&#x7684;Application.mk&#x6587;&#x4EF6; &#x653E;&#x5728;project/jni/&#x76EE;&#x5F55;&#x4E0B; &#xFF08;project&#x4EE3;&#x8868;&#x4F60;&#x6240;&#x5199;&#x7A0B;&#x5E8F;&#x7684;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#xFF09;&#xFF0C;&#x8FD9;&#x6837;ndk-build&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x81EA;&#x52A8;&#x641C;&#x7D22;&#x5230;&#x5B83;&#x3002;
</code></pre>
<h2 id="applicationmk-&#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;"><a name="applicationmk-&#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;" class="anchor-navigation-ex-anchor" href="#applicationmk-&#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8. Application.mk &#x914D;&#x7F6E;&#x7684;&#x4F5C;&#x7528;&#x548C;&#x8303;&#x56F4;</h2>
<pre><code class="lang-text">1&#x3001;&#x6307;&#x660E; &#x76EE;&#x6807;&#x5E73;&#x53F0;&#x7684;ABI&#x7C7B;&#x578B;  
2&#x3001;&#x6307;&#x660E; &#x5DE5;&#x7A0B;&#x662F; release/debug&#x6A21;&#x5F0F;
3&#x3001;&#x6307;&#x660E; C++&#x6807;&#x51C6;&#x5E93;&#x7C7B;&#x578B;
4&#x3001;&#x6307;&#x5B9A; Toolchains(&#x5DE5;&#x5177;&#x94FE;)
</code></pre>
<h2 id="applicationmk-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><a name="applicationmk-&#x7B80;&#x5355;&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#applicationmk-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>2.9. Application.mk &#x7B80;&#x5355;&#x793A;&#x4F8B;</h2>
<pre><code class="lang-text">LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE = libhellos
LOCAL_CFLAGS = $(L_CFLAGS)
LOCAL_SRC_FILES = hellos.c
LOCAL_C_INCLUDES = $(INCLUDES)
LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_COPY_HEADERS_TO := libhellos
LOCAL_COPY_HEADERS := hellos.h
include $(BUILD_STATIC_LIBRARY)
#&#x7F16;&#x8BD1;&#x52A8;&#x6001;&#x5E93;
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE = libhellod
LOCAL_CFLAGS = $(L_CFLAGS)
LOCAL_SRC_FILES = hellod.c
LOCAL_C_INCLUDES = $(INCLUDES)
LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_COPY_HEADERS_TO := libhellod
LOCAL_COPY_HEADERS := hellod.h
include $(BUILD_SHARED_LIBRARY)
#&#x4F7F;&#x7528;&#x9759;&#x6001;&#x5E93;
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellos
LOCAL_STATIC_LIBRARIES := libhellos
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS += -ldl
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := mains.c
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
#&#x4F7F;&#x7528;&#x52A8;&#x6001;&#x5E93;
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellod
LOCAL_MODULE_TAGS := debug
LOCAL_SHARED_LIBRARIES := libc libcutils libhellod
LOCAL_LDLIBS += -ldl
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := maind.c
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
</code></pre>
<h2 id="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;_1"><a name="&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;_1" class="anchor-navigation-ex-anchor" href="#&#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;_1"><i class="fa fa-link" aria-hidden="true"></i></a>2.10. &#x7CFB;&#x7EDF;&#x81EA;&#x5E26;&#x7684;&#x53D8;&#x91CF;</h2>
<table>
<thead>
<tr>
<th>NDK &#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;</th>
<th>&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td>APP_PROJECT_PATH</td>
<td>&#x6307;&#x5B9A;&#x5E94;&#x7528;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x3002; Application.mk &#x6587;&#x4EF6;&#x653E;&#x5982;&#x679C;&#x5728; $PROJECT/jni/ &#x4E0B;&#xFF0C;&#x6B64;&#x53D8;&#x91CF;&#x53EF;&#x9009;&#x3002;</td>
</tr>
<tr>
<td>APP_OPTIM</td>
<td>&#x9ED8;&#x8BA4;release</td>
</tr>
<tr>
<td>APP_CFLAGS</td>
<td>&#x4E3A;&#x4EFB;&#x4F55;&#x6A21;&#x5757;&#x7F16;&#x8BD1;&#x4EFB;&#x4F55; C &#x6216; C++ &#x6E90;&#x4EE3;&#x7801;&#x65F6;&#x4F20;&#x9012;&#x5230;&#x7F16;&#x8BD1;&#x5668;&#x7684;&#x4E00;&#x7EC4; C &#x7F16;&#x8BD1;&#x5668;&#x6807;&#x5FD7;</td>
</tr>
<tr>
<td>APP_CPPFLAGS</td>
<td>&#x5728;&#x4EC5;&#x6784;&#x5EFA; C++ &#x6E90;&#x6587;&#x4EF6;&#x65F6;&#x4F20;&#x9012;&#x5230;&#x7F16;&#x8BD1;&#x5668;&#x7684;&#x4E00;&#x7EC4; C++ &#x7F16;&#x8BD1;&#x5668;&#x6807;&#x5FD7;</td>
</tr>
<tr>
<td>APP_LDFLAGS</td>
<td>&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x5728;&#x94FE;&#x63A5;&#x5E94;&#x7528;&#x65F6;&#x4F20;&#x9012;&#x7684;&#x4E00;&#x7EC4;&#x94FE;&#x63A5;&#x5668;&#x6807;&#x5FD7;&#x3002;</td>
</tr>
<tr>
<td>APP_BUILD_SCRIPT</td>
<td>&#x6307;&#x5B9A;Android.mk&#x7684;&#x9ED8;&#x8BA4;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>APP_ABI</td>
<td></td>
</tr>
<tr>
<td>APP_PLATFORM</td>
<td>&#x5305;&#x542B;&#x76EE;&#x6807; Android &#x5E73;&#x53F0;&#x7684;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td>APP_STL</td>
<td></td>
</tr>
<tr>
<td>APP_SHORT_COMMANDS</td>
<td></td>
</tr>
<tr>
<td>NDK_TOOLCHAIN_VERSION</td>
<td>&#x5B9A;&#x4E49;&#x4E3A; 4.9 &#x6216; 4.8 &#x4EE5;&#x9009;&#x62E9; GCC &#x7F16;&#x8BD1;&#x5668;&#x7684;&#x7248;&#x672C;</td>
</tr>
<tr>
<td>APP_PIE</td>
<td></td>
</tr>
<tr>
<td>APP_THIN_ARCHIVE</td>
<td></td>
</tr>
</tbody>
</table>
<h1 id="cmake-&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><a name="cmake-&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#cmake-&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3. cmake &#x7F16;&#x8BD1;&#x65B9;&#x5F0F;</h1>
<p>Android &#x5BF9; CMake&#x7684;&#x8BF4;&#x660E;&#x8BF7;&#x53C2;&#x8003; <a href="https://developer.android.com/ndk/guides/cmake.html#variables" target="_blank">CMake API </a>  &#x3001; <a href="https://cmake.org/" target="_blank">CMake&#x5B98;&#x7F51;</a></p>
<pre><code class="lang-text">androidStudio &#x5728;2.2&#x4E4B;&#x524D;&#x5BF9; C/C++ &#x652F;&#x6301;&#x4E0D;&#x662F;&#x5F88;&#x53CB;&#x597D;&#xFF0C;&#x6CA1;&#x6709;&#x8BED;&#x6CD5;&#x63D0;&#x793A;&#xFF0C;&#x914D;&#x7F6E;&#x7F16;&#x8BD1;&#x4E5F;&#x4E0D;&#x65B9;&#x4FBF; &#x3002;
&#x4ECE;androidStudio 2.2&#x6B63;&#x5F0F;&#x7248;&#x5F00;&#x59CB; &#xFF0C;&#x91C7;&#x7528;&#x4E86;cmake&#x65B9;&#x5F0F;&#x7F16;&#x8BD1;&#xFF0C;&#x7B80;&#x5316;&#x4E86;&#x7F16;&#x8BD1;&#x914D;&#x7F6E; &#x3002;
&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x518D;&#x624B;&#x52A8;&#x8F93;&#x5165; javac&#x3001;javah&#x547D;&#x4EE4;&#x7B49;&#x3002;
</code></pre>
<h2 id="cmake"><a name="cmake" class="anchor-navigation-ex-anchor" href="#cmake"><i class="fa fa-link" aria-hidden="true"></i></a>3.1. CMake</h2>
<p>Android Studio &#x9ED8;&#x8BA4;&#x4F7F;&#x7528; CMake &#x7F16;&#x8BD1;&#x539F;&#x751F;&#x5E93;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x53EA;&#x6253;&#x7B97;&#x7528;ndk-build&#x6765;&#x7F16;&#x8BD1;&#x7684;&#x8BDD;&#xFF0C;&#x4F60;&#x5C31;&#x4E0D;&#x9700;&#x8981;&#x8FD9;&#x4E2A;&#x7EC4;&#x4EF6;&#x3002;CMake&#x662F;AndroidStudio2.2&#x63D0;&#x4F9B;&#x7684;&#x6784;&#x5EFA;C&#x9879;&#x76EE;&#x7684;&#x5DE5;&#x5177;</p>
<h2 id="lldb"><a name="lldb" class="anchor-navigation-ex-anchor" href="#lldb"><i class="fa fa-link" aria-hidden="true"></i></a>3.2. LLDB</h2>
<p>&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x8C03;&#x8BD5;&#x672C;&#x5730;&#x4EE3;&#x7801;&#x3002;</p>
<h2 id="androidstudio22-&#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;"><a name="androidstudio22-&#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;" class="anchor-navigation-ex-anchor" href="#androidstudio22-&#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3. androidstudio2.2+ &#x8F93;&#x51FA;c&#x4EE3;&#x7801;log&#x4FE1;&#x606F;</h2>
<pre><code class="lang-html">1&#x3001; error: undefined reference to &apos;__android_log_print&apos;
app&#x5C42;&#x7684; gradle &#x4E2D; defaultConfig &#x6807;&#x7B7E;&#x4E0B; &#x8FDB;&#x884C;&#x914D;&#x7F6E;
ndk {
    //&#x5C31;&#x662F;&#x4F9D;&#x8D56;ndk&#x5DE5;&#x5177;&#x5305;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;liblog.so&#x6587;&#x4EF6;
ldLibs &quot;log&quot;
}
2&#x3001;cmake&#x4E2D;&#x5BF9;log&#x7684;&#x914D;&#x7F6E;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684;&#x5373;&#x53EF; &#x3002;

3&#x3001;//&#x5BFC;&#x5165;log&#x5305;
#include <span class="hljs-tag">&lt;<span class="hljs-name">android</span>/<span class="hljs-attr">log.h</span>&gt;</span>
//&#x5B9A;&#x4E49;log&#x6807;&#x7B7E;&#xFF0C;&#x540D;&#x5B57;&#x968F;&#x610F;
#define LOG_TAG  &quot;C_TAG&quot;
//&#x5B9A;&#x4E49;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;
#define LOGD(...)  __android_log_print  (ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
//&#x6253;&#x5370;log
jint value = 1000 ;
LOGD(&quot;value=%d&quot;, value);
LOGD(&quot;value=%d&quot;, 100);

4&#x3001;&#x6709;&#x4E9B;&#x624B;&#x673A;&#x80FD;&#x8F93;&#x51FA;Java&#x4E2D;&#x7684;log&#xFF0C;&#x5374;&#x4E0D;&#x80FD;&#x8F93;&#x51FA;c&#x4EE3;&#x7801;&#x4E2D;&#x7684;log &#x3002;
&#x539F;&#x56E0;&#x53EF;&#x80FD;&#x8DDF;&#x624B;&#x673A;&#x7684;&#x8BBE;&#x7F6E;&#x6709;&#x5173;&#x7CFB;&#x3002; &#x5728;&#x5F00;&#x53D1;&#x8005;&#x9009;&#x9879;&#x4E2D;&#x8FDB;&#x884C;&#x76F8;&#x5173;&#x8BBE;&#x7F6E;&#x5373;&#x53EF;&#x3002;
</code></pre>
<h2 id="buildgradle-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><a name="buildgradle-&#x90E8;&#x5206;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#buildgradle-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>3.4. build.gradle &#x90E8;&#x5206;&#x914D;&#x7F6E;</h2>
<pre><code class="lang-text">// &#x6307;&#x660E;&#x9879;&#x76EE;&#x4E2D;&#x9700;&#x8981;&#x7528;&#x5230;&#x7684; &#x7B2C;&#x4E09;&#x65B9;&#x7684; .so , .a &#x6587;&#x4EF6;
sourceSets {
    main {
        // &#x5982;&#x679C;&#x4E0D;&#x914D;&#x7F6E;&#xFF0C;android&#x5C31;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x8DEF;&#x5F84;
        jniLibs.srcDirs = [&apos;src/main/jniLibs&apos;]
        // &#x5982;&#x679C;&#x559C;&#x6B22;&#x653E; libs&#x76EE;&#x5F55;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD9;&#x6837;&#x5199;
        //jniLibs.srcDirs = [&apos;libs&apos;]
    }
}

ndk{
    // &#x6307;&#x660E;&#x53EA;&#x7F16;&#x8BD1;&#x7684;&#x5BF9;&#x5E94;&#x7684;cpu&#x7C7B;&#x578B;
    abiFilters &quot;armeabi-v7a&quot;
}

cmake {
    cppFlags &quot;-std=c++11 -frtti -fexceptions&quot;
    // &#x8BA9;CMake&#x6784;&#x5EFA;&#x539F;&#x751F;&#x5E93;&#x65F6;&#x652F;&#x6301;&#x201C;NEON&#x201D;,&#x9ED8;&#x8BA4;&#x7684;&#x662F;&#x4E0D;&#x652F;&#x6301;
    arguments &quot;-DANDROID_ARM_NEON=TRUE&quot;
}
</code></pre>
<pre><code class="lang-text">packagingOptions  // &#x7528;&#x6765;&#x5BF9; gradle&#x505A;&#x4E00;&#x4E9B;&#x914D;&#x7F6E;
exclude      //&#x8FC7;&#x6EE4;&#x6389;&#x67D0;&#x4E9B;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x76EE;&#x5F55;&#x4E0D;&#x6DFB;&#x52A0;&#x5230;APK&#x4E2D; 
pickFirst   // &#x5339;&#x914D;&#x5230;&#x591A;&#x4E2A;&#x76F8;&#x540C;&#x6587;&#x4EF6;&#xFF0C;&#x53EA;&#x63D0;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A; &#x3002;
merge       // &#x5339;&#x914D;&#x7684;&#x6587;&#x4EF6;&#x90FD;&#x6DFB;&#x52A0;&#x5230;APK&#x4E2D;&#xFF0C;&#x548C;pickFirst&#x6709;&#x4E9B;&#x76F8;&#x53CD;&#xFF0C;&#x4F1A;&#x5408;&#x5E76;&#x6240;&#x6709;&#x6587;&#x4EF6;&#x3002;
doNotStrip  //&#x8BBE;&#x7F6E;&#x67D0;&#x4E9B;&#x52A8;&#x6001;&#x5E93;&#x4E0D;&#x88AB;&#x4F18;&#x5316;&#x538B;&#x7F29;&#x3002;
</code></pre>
<h2 id="cmakeliststxt-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><a name="cmakeliststxt-&#x90E8;&#x5206;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#cmakeliststxt-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>3.5. CMakeLists.txt &#x90E8;&#x5206;&#x914D;&#x7F6E;</h2>
<pre><code class="lang-text">#&#x8FD9;&#x91CC;&#x8BBE;&#x5B9A;&#x5DE5;&#x7A0B;&#x8DEF;&#x5F84;  &#xFF0C; &#x7B49;&#x540C;&#x4E8E;  CMAKE_SOURCE_DIR
# set(PROGRAM_PATH &quot;E:/test-fffffmpeg/WkNative/app&quot;)

# &#x6279;&#x91CF;&#x5BFC;&#x5165;rtsp &#x76F8;&#x5173;&#x4EE3;&#x7801;
file( GLOB_RECURSE wkrtsp_cpp &quot;src/main/cpp/rtspclient/src/*.cpp&quot;)
file( GLOB_RECURSE wkrtsp_c &quot;src/main/cpp/rtspclient/src/*.c&quot;)
add_library(wkrtsp-lib
             SHARED
             ${wkrtsp_c}
             ${wkrtsp_cpp})

#&#x5BFC;&#x5165;&#x5DF2;&#x7ECF;&#x7F16;&#x8BD1;&#x597D;&#x7684;opencv&#x5E93;-&#x5934;&#x6587;&#x4EF6;
include_directories( src/main/cpp/OpenCV/include )
# &#x5BFC;&#x5165; opencv &#x7684;so
add_library(libopencv_world
            SHARED
            IMPORTED )
set_target_properties( libopencv_world
                       PROPERTIES
                       IMPORTED_LOCATION
                       ${CMAKE_SOURCE_DIR}/src/main/jniLibs/armeabi-v7a/libopencv_world.so
                       )
</code></pre>
<h2 id="cmakeliststxt-&#x8BF4;&#x660E;"><a name="cmakeliststxt-&#x8BF4;&#x660E;" class="anchor-navigation-ex-anchor" href="#cmakeliststxt-&#x8BF4;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>3.6. CMakeLists.txt &#x8BF4;&#x660E;</h2>
<pre><code class="lang-text"># &#x6DFB;&#x52A0;&#x4E86;c++11&#x7684;&#x652F;&#x6301;
set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} -std=gnu++11&quot;)
# &#x6B64;&#x6807;&#x5FD7;&#x5728;&#x94FE;&#x63A5;&#x6210;&#x5171;&#x4EAB;&#x5E93;&#x65F6;&#x6709;&#x6548;
set(CMAKE_SHARED_LINKER_FLAGS &quot;${CMAKE_SHARED_LINKER_FLAGS} -Wall -v -Wl,--no-warn-shared-textrel&quot;)

# &#x7CFB;&#x7EDF;&#x5E93;&#xFF0C;&#x6253;&#x5370;&#x65E5;&#x5FD7;
find_library( log-lib  log )
# &#x7CFB;&#x7EDF;&#x5E93; &#xFF0C;&#x538B;&#x7F29;&#x5E93;
find_library( z-lib  z )
# &#x6570;&#x5B66;&#x8BA1;&#x7B97;
find_library( m-lib  m )
</code></pre>
<h2 id="&#x5176;&#x4ED6;&#x914D;&#x7F6E;"><a name="&#x5176;&#x4ED6;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>3.7. &#x5176;&#x4ED6;&#x914D;&#x7F6E;</h2>
<pre><code class="lang-text">enable_language(ASM) //&#x652F;&#x6301;&#x6C47;&#x7F16;
configure_file () // &#x4EE3;&#x7801;&#x6587;&#x4EF6;&#x4E2D;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;CMake&#x4E2D;&#x7684;&#x53D8;&#x91CF;
set( KEY, value)  // &#x952E;&#x503C;&#x5BF9;,  &#x8BBE;&#x7F6E;KEY&#x7684;&#x503C;&#x4E3A;value&#x3002;&#x83B7;&#x53D6;&#x65B9;&#x5F0F;&#x4E3A; ${KEY} 
unset () //&#x53D6;&#x6D88;&#x952E;&#x503C;&#x5BF9;&#x8BBE;&#x7F6E;
list ()  // &#x7528;&#x6765;&#x505A;&#x4E00;&#x4E9B;&#x64CD;&#x4F5C;&#xFF0C;&#x4F8B;&#x5982;LENGTH &#x3001;APPEND &#x3001;FIND &#x3001;REMOVE_AT &#x7B49;
add_definitions () // &#x589E;&#x52A0;&#x7F16;&#x8BD1;&#x53C2;&#x6570;
add_custom_command () // &#x6DFB;&#x52A0;&#x81EA;&#x5B9A;&#x4E49;&#x547D;&#x4EE4;
add_subdirectory () // &#x5C06;&#x6307;&#x5B9A;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x52A0;&#x5230;build&#x4EFB;&#x52A1;&#x5217;&#x8868;&#x4E2D;&#x3002;
install ()  // &#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x5B89;&#x88C5;&#x89C4;&#x5219;&#xFF0C;&#x5B89;&#x88C5;&#x7684;&#x5185;&#x5BB9;&#x53EF;&#x4EE5;&#x5305;&#x62EC;&#x76EE;&#x6807;&#x4E8C;&#x8FDB;&#x5236;&#x3001;&#x52A8;&#x6001;&#x5E93;&#x3001;&#x9759;&#x6001;&#x5E93;&#x4EE5;&#x53CA;  &#x6587;&#x4EF6;&#x3001;&#x76EE;&#x5F55;&#x3001;&#x811A;&#x672C;&#x7B49;
include_directories () //&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;
add_library () //&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5E93;
add_executable () // &#x5F15;&#x5165;&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;
set_target_properties () // &#x5C06;&#x5404;&#x79CD; so &#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x8F6C;&#x5316;&#x6210;&#x7B80;&#x5355;&#x7684;&#x503C;
find_library () // &#x5BFB;&#x627E;&#x672C;&#x5730;&#x5B58;&#x5728;&#x7684;&#x5E93;&#x7684;&#x8DEF;&#x5F84;,&#x4F8B;&#x5982;&#x65E5;&#x5FD7;&#x6253;&#x5370;&#x5E93;log
link_directories ()    // &#x6DFB;&#x52A0;&#x52A8;&#x6001;&#x8FDE;&#x63A5;&#x5E93;&#x7684;&#x8DEF;&#x5F84;
target_link_libraries ()// &#x5C06;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x4E0E;&#x5E93;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x94FE;&#x63A5;.
target_include_directories ()  // &#x4E5F;&#x662F;&#x7528;&#x6765;&#x914D;&#x7F6E;&#x5934;&#x6587;&#x4EF6;
target_compile_options () // &#x6307;&#x5B9A;&#x7F16;&#x8BD1;&#x9009;&#x9879;
file(GLOB xxx &quot;${PATH_TO_MEDIACORE}/camera/*.cc&quot;)   // file&#x51FD;&#x6570;&#xFF0C;&#x81EA;&#x52A8;&#x5C06;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x7B26;&#x5408;&#x540E;&#x7F00;&#x7684;&#x6587;&#x4EF6;&#x52A0;&#x5165;&#x5230;xxx&#x53D8;&#x91CF;&#x4E2D;&#xFF0C;GLOB/GLOB_RECURSE  &#x662F;&#x4E00;&#x79CD;&#x52A0;&#x5165;&#x7B56;&#x7565;&#xFF0C; 
project (XXX)  // &#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x7684;&#x540D;&#x5B57;&#x53EB;xxx
message ([&lt;mode&gt;] &quot;message to display&quot; ...) //&#x8F93;&#x51FA;&#x6253;&#x5370;&#x4FE1;&#x606F; &#xFF0C; mode= none / STATUS /WARNING /FATAL_ERROR &#x7B49;
add_executable (xxx  bbb.cpp)   //&#x4E3A; xxx&#x8FD9;&#x4E2A; project &#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x7684;&#x6587;&#x4EF6;bbb.cpp
option(&lt;variable&gt; &quot;&lt;help_text&gt;&quot; [value]) //&#x53D8;&#x91CF;&#x540D; + &#x63CF;&#x8FF0;&#x4FE1;&#x606F; + &#x521D;&#x59CB;&#x503C;(&#x53EA;&#x80FD;&#x662F;ON&#x6216;OFF)
if &#x3001;foreach&#x3001;while //  &#x6761;&#x4EF6;&#x5224;&#x65AD;
macro (xx  bb) // &#x5F00;&#x59CB;&#x5B8F;&#x5B9A;&#x4E49;
endmacro () // &#x7ED3;&#x675F;&#x5B8F;&#x5B9A;&#x4E49;
function () // &#x5F00;&#x59CB;&#x51FD;&#x6570;&#x5B9A;&#x4E49;
endfunction () //&#x7ED3;&#x675F;&#x51FD;&#x6570;&#x5B9A;&#x4E49;

CMAKE_SOURCE_DIR  // &#x5185;&#x7F6E;&#x5E38;&#x91CF; &#xFF0C; &#x8868;&#x793A;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;
CMAKE_CURRENT_LIST_DIR // &#x5185;&#x7F6E;&#x5E38;&#x91CF; &#xFF0C; &#x5F53;&#x524D;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x76EE;&#x5F55;
PROJECT_SOURCE_DIR   // &#x5185;&#x7F6E;&#x5E38;&#x91CF; &#xFF0C;&#x8868;&#x793A;&#x7684;&#x662F;&#x6E90;&#x4EE3;&#x7801;&#x7684;&#x8DEF;&#x5F84;&#x3002;
PROJECT_BINARY_DIR   //&#x5185;&#x7F6E;&#x5E38;&#x91CF; &#xFF0C;&#x8868;&#x793A;&#x7684;&#x662F;cmake build &#x7684;&#x8DEF;&#x5F84;
ANDROID_PLATFORM_LEVEL //&#x7CFB;&#x7EDF;&#x7248;&#x672C;
ANDROID_ABI   // &#x8BBE;&#x5907;cpu&#x67B6;&#x6784;&#x7C7B;&#x578B;
STRLESS&#x3001;STRGREATER&#x3001;STREQUAL    // &#x5B57;&#x7B26;&#x4E32;&#x6BD4;&#x8F83;
LESS&#x3001;GREATER&#x3001;EQUAL  //&#x6570;&#x5B57;&#x6BD4;&#x8F83;
CMAKE_BUILD_TYPE  //cmake&#x7684;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F; &#xFF0C;&#x8C03;&#x8BD5;&#x7248;&#x8FD8;&#x662F;&#x6B63;&#x5F0F;&#x7248; Debug &#xFF0C;Release
PROPERTIES  //&#x7528;&#x6765;&#x6307;&#x5B9A;&#x5E93;&#x7684;&#x4E00;&#x4E9B;&#x7F16;&#x8BD1;&#x5C5E;&#x6027;
IMPORTED_LOCATION  // &#x5E93;&#x7684;&#x5730;&#x5740;
CMAKE_SYSTEM  // &#x7CFB;&#x7EDF;&#x5168;&#x540D; 
CMAKE_SYSTEM_NAME //&#x7CFB;&#x7EDF;&#x540D;&#x79F0; 
CMAKE_SYSTEM_VERSION // &#x7CFB;&#x7EDF;&#x7248;&#x672C;
CMAKE_SYSTEM_PROCESSOR  //CPU&#x540D;&#x79F0;
MATCHES  // &#x7528;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x53BB;&#x5339;&#x914D;&#x5230;&#x7ED9;&#x5B9A;&#x7684;&#x5185;&#x5BB9;
</code></pre>
<h1 id="jni"><a name="jni" class="anchor-navigation-ex-anchor" href="#jni"><i class="fa fa-link" aria-hidden="true"></i></a>4. jni</h1>
<p>&#x57FA;&#x4E8E; Androidstudio &#x3001;cmake &#x3001; c/c++  &#x3002;&#x6CE8;&#x610F;&#xFF1A;jni&#x5C42;&#x53BB;&#x8BFB;&#x53D6;SD&#x5361;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x5728;AndroidManifest.xml&#x914D;&#x7F6E;&#x6743;&#x9650;&#x3002; </p>
<h2 id="jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><a name="jni-&#x4F7F;&#x7528;&#x573A;&#x666F;" class="anchor-navigation-ex-anchor" href="#jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1. JNI &#x4F7F;&#x7528;&#x573A;&#x666F;</h2>
<pre><code class="lang-text">1&#x3001;&#x63D0;&#x9AD8;&#x4EE3;&#x7801;&#x5B89;&#x5168;&#x6027;&#x3002;&#x56E0;&#x4E3A;.so&#x6587;&#x4EF6;&#x53CD;&#x7F16;&#x8BD1;&#x56F0;&#x96BE;&#x3002;&#xFF08;&#x52A0;&#x5BC6;&#x4E00;&#x4E9B;&#x7B97;&#x6CD5;&#x7B49;&#xFF09;
2&#x3001;&#x65B9;&#x4FBF;&#x4F7F;&#x7528;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;c/c++&#x5E93;&#x3002;&#x53EF;&#x4EE5;&#x52A0;&#x8F7D; .dll &#x548C; .so &#x683C;&#x5F0F;&#x7684;&#x52A8;&#x6001;&#x5E93;&#x3002;
3&#x3001;&#x63D0;&#x9AD8;&#x67D0;&#x4E9B;&#x7279;&#x5B9A;&#x60C5;&#x51B5;&#x4E0B;&#x7684;&#x6267;&#x884C;&#x6548;&#x7387;&#x3002;&#xFF08;c/c++&#x7684;&#x6548;&#x7387;&#x6BD4;java&#x9AD8;&#x3002;&#x4E0D;&#x8FC7;&#x5E76;&#x4E0D;&#x80FD;&#x660E;&#x663E;&#x63D0;&#x5347;android&#x7A0B;&#x5E8F;&#x7684;&#x6027;&#x80FD;&#xFF09;
</code></pre>
<h2 id="jni&#x8BED;&#x6CD5;"><a name="jni&#x8BED;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#jni&#x8BED;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>4.2. JNI&#x8BED;&#x6CD5;</h2>
<pre><code class="lang-text">#ifdef __cplusplus
extern &quot;C&quot;
#endif
// &#x5982;&#x679C;&#x662F;c++&#x4EE3;&#x7801;&#xFF0C;&#x4E5F;&#x7EDF;&#x4E00;&#x7528;c&#x7684;&#x8BED;&#x6CD5;&#x53BB;&#x7F16;&#x8BD1;&#x3002;
#ifdef __cplusplus
extern &quot;}&quot;
#endif


extern &quot;C&quot; JNIEXPORT void JNICALL
Java_com_xxx_nPlay(JNIEnv *env, jobject instance, jstring url_) { 
 ...
}

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_kgdwbb_jnistudy_MainActivity_helloJNI(JNIEnv* env, jobject thiz,jstring msg) {
    //do something
}
extern &quot;C&quot;  // &#x4EE3;&#x7801;&#x662F;&#x7528;C++&#x8BED;&#x8A00;&#x5199;&#x7684;&#x5C31;&#x9700;&#x8981;&#x7528;&#x8FD9;&#x4E2A;&#xFF0C;  C&#x8BED;&#x8A00;&#x7F16;&#x5199;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x3002;
JNIEXPORT   // &#x6807;&#x8BB0;&#x4E3A;&#x8BE5;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x90E8;&#x8C03;&#x7528;&#xFF0C;&#x7C7B;&#x4F3C;Java&#x7684;public&#x51FD;&#x6570;&#x548C;private&#x51FD;&#x6570;&#x7684;&#x533A;&#x522B;&#x3002;
JNICALL     // &#x8BF4;&#x660E;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x4E00;&#x4E2A;JNI&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x548C;&#x666E;&#x901A;&#x7684;C/C++&#x51FD;&#x6570;&#x8FDB;&#x884C;&#x533A;&#x522B;&#x3002;
</code></pre>
<h3 id="jnienv"><a name="jnienv" class="anchor-navigation-ex-anchor" href="#jnienv"><i class="fa fa-link" aria-hidden="true"></i></a>4.2.1. JNIEnv</h3>
<pre><code class="lang-text">JNIEnv&#x662F; JavaVM &#x5728;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;&#x4EE3;&#x8868;, &#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x90FD;&#x6709;&#x4E00;&#x4E2A;, JNI &#x4E2D;&#x53EF;&#x80FD;&#x6709;&#x5F88;&#x591A;&#x4E2A; JNIEnv;
&#x6BCF;&#x4E2A;JNIEnv &#x90FD;&#x662F;&#x7EBF;&#x7A0B;&#x4E13;&#x6709;&#x7684;, &#x5176;&#x5B83;&#x7EBF;&#x7A0B;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x672C;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684; JNIEnv, &#x7EBF;&#x7A0B; A &#x4E0D;&#x80FD;&#x8C03;&#x7528; &#x7EBF;&#x7A0B; B &#x7684; JNIEnv;
&#x4F46;&#x662F;&#xFF0C;&#x4E00;&#x4E2A;&#x672C;&#x5730;&#x65B9;&#x6CD5;&#x53EF;&#x88AB;&#x4E0D;&#x540C;&#x7684; Java &#x7EBF;&#x7A0B;&#x6240;&#x8C03;&#x7528;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E0D;&#x540C;&#x7684; JNIEnv&#x3002;

//JNIEnv &#x4F5C;&#x7528;
1&#x3001;&#x8C03;&#x7528;Java&#x51FD;&#x6570;
JNIEnv&#x4EE3;&#x8868;Java&#x8FD0;&#x884C;&#x73AF;&#x5883;,&#x53EF;&#x4EE5;&#x4F7F;&#x7528;JNIEnv&#x8C03;&#x7528;Java&#x4E2D;&#x7684;&#x4EE3;&#x7801;;

2&#x3001;&#x64CD;&#x4F5C;Java&#x5BF9;&#x8C61;
Java&#x5BF9;&#x8C61;&#x4F20;&#x5165;JNI&#x5C42;&#x5C31;&#x662F;Jobject&#x5BF9;&#x8C61;, &#x9700;&#x8981;&#x4F7F;&#x7528;JNIEnv&#x6765;&#x64CD;&#x4F5C;&#x8FD9;&#x4E2A;Java&#x5BF9;&#x8C61;;
</code></pre>
<h2 id="jni-&#x52A8;&#x6001;&#x6CE8;&#x518C;-&#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;"><a name="jni-&#x52A8;&#x6001;&#x6CE8;&#x518C;-&#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;" class="anchor-navigation-ex-anchor" href="#jni-&#x52A8;&#x6001;&#x6CE8;&#x518C;-&#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;"><i class="fa fa-link" aria-hidden="true"></i></a>4.3. JNI &#x52A8;&#x6001;&#x6CE8;&#x518C; &#x3001;&#x9759;&#x6001;&#x6CE8;&#x518C;</h2>
<pre><code class="lang-text">&#x65E0;&#x8BBA;&#x662F;&#x52A8;&#x9759;&#x6001;&#x6CE8;&#x518C;&#x8FD8;&#x662F;&#x52A8;&#x6001;&#x6CE8;&#x518C;&#xFF0C;
Java&#x7AEF;&#x4EE3;&#x7801;&#x90FD;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;
&#x533A;&#x522B;&#x5728;&#x4E8E; C/C++&#x91CC;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5F62;&#x5F0F;

// &#x9759;&#x6001;&#x6CE8;&#x518C;&#xFF0C;&#x7B80;&#x5355;&#x6613;&#x61C2;&#xFF0C;Androidstudio &#x81EA;&#x52A8;&#x751F;&#x6210;&#x5C31;&#x91C7;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;
extern &quot;C&quot; JNIEXPORT jstring JNICALL
Java_com_mirkowu_jintest_jni_JniTest_stringFromJNI(JNIEnv *env, jclass clazz) {
    std::string hello = &quot;Hello from C++  by &#x9759;&#x6001;&#x6CE8;&#x518C;&quot;;
    return env-&gt;NewStringUTF(hello.c_str());
}

// &#x52A8;&#x6001;&#x6CE8;&#x518C;&#xFF0C;&#x4E8B;&#x5148;&#x7EF4;&#x62A4;&#x597D;&#x4E00;&#x5F20;&#x8868;&#xFF0C;&#x5C06; Java&#x548C; native &#x7AEF;&#x7684;&#x65B9;&#x6CD5;&#x540D;&#x5BF9;&#x5E94;&#x8D77;&#x6765;&#xFF0C;&#x6548;&#x7387;&#x76F8;&#x5BF9;&#x9AD8;&#x4E00;&#x70B9;
static JNINativeMethod method_table[] = {
        // &#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;a &#x662F;java native&#x65B9;&#x6CD5;&#x540D;&#xFF0C;
        // &#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570; &#x662F;native&#x65B9;&#x6CD5;&#x53C2;&#x6570;,&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x662F;&#x4F20;&#x5165;&#x53C2;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x5916;&#x8FB9;&#x7684;&#x662F;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#xFF0C;
        // &#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570; &#x662F;c/c++&#x65B9;&#x6CD5;&#x53C2;&#x6570;,&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x662F;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#xFF0C;
        {&quot;a&quot;, &quot;()Ljava/lang/String;&quot;,                                     (jstring *) aaa},
        {&quot;b&quot;, &quot;(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;&quot;, (jstring *) getStringWithDynamicReg},

};
</code></pre>
<h2 id="jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><a name="jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.4. JNI&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<table>
<thead>
<tr>
<th>java&#x57FA;&#x672C;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>bit</th>
<th>-</th>
<th>java&#x57FA;&#x672C;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>bit</th>
</tr>
</thead>
<tbody>
<tr>
<td>boolean</td>
<td>jboolean</td>
<td>8</td>
<td></td>
<td>int</td>
<td>jint</td>
<td>32</td>
</tr>
<tr>
<td>byte</td>
<td>jbyte</td>
<td>8</td>
<td></td>
<td>long</td>
<td>jlong</td>
<td>64</td>
</tr>
<tr>
<td>char</td>
<td>jchar</td>
<td>16</td>
<td></td>
<td>float</td>
<td>jfloat</td>
<td>32</td>
</tr>
<tr>
<td>short</td>
<td>jshort</td>
<td>16</td>
<td></td>
<td>double</td>
<td>jdouble</td>
<td>64</td>
</tr>
<tr>
<td>void</td>
<td>void</td>
<td>&#x65E0;</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>java&#x5F15;&#x7528;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>-</th>
<th>java&#x5F15;&#x7528;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B; </th>
</tr>
</thead>
<tbody>
<tr>
<td>Object</td>
<td>jobject</td>
<td></td>
<td>short[ ]</td>
<td>jshortArray </td>
</tr>
<tr>
<td>Class</td>
<td>jclass</td>
<td></td>
<td>int[ ]</td>
<td>jintArray   </td>
</tr>
<tr>
<td>String</td>
<td>jstring</td>
<td></td>
<td>long[ ]</td>
<td>jlongArray  </td>
</tr>
<tr>
<td>Object[ ]</td>
<td>jobjectArray</td>
<td></td>
<td>float[ ]</td>
<td>jfloatArray </td>
</tr>
<tr>
<td>boolean[ ]</td>
<td>jbooleanArray</td>
<td></td>
<td>double[ ]</td>
<td>jdoubleArray</td>
</tr>
<tr>
<td>byte[ ]</td>
<td>jbyteArray</td>
<td></td>
<td>Throwable</td>
<td>jthrowable  </td>
</tr>
<tr>
<td>char[ ]</td>
<td>jcharArray</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="&#x5B57;&#x7B26;&#x4E32;"><a name="&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>4.5. &#x5B57;&#x7B26;&#x4E32;</h2>
<pre><code class="lang-text">std::string helloCpp = &quot;Hello from C++ , aivin&quot;;
showLog(&quot;--&gt; %s&quot; ,helloCpp.c_str()) ;
</code></pre>
<h2 id="jni&#x7B7E;&#x540D;"><a name="jni&#x7B7E;&#x540D;" class="anchor-navigation-ex-anchor" href="#jni&#x7B7E;&#x540D;"><i class="fa fa-link" aria-hidden="true"></i></a>4.6. JNI&#x7B7E;&#x540D;</h2>
<p>java&#x4E2D;&#xFF0C;&#x5BF9;&#x4E8E;&#x67D0;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6765;&#x8BF4;&#xFF0C; &#x53EF;&#x4EE5;&#x7528;&#x8FC7;&#x65B9;&#x6CD5;&#x540D;&#x548C;&#x53C2;&#x6570; &#x5C31;&#x53EF;&#x4EE5;&#x786E;&#x5B9A;&#x552F;&#x4E00;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x3002;&#x5728;JNI&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;&#x51FD;&#x6570;&#x540D;&#x548C; &#x7B7E;&#x540D;&#x4FE1;&#x606F; &#x53EF;&#x4EE5;&#x786E;&#x5B9A;&#x552F;&#x4E00;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><a name="&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>4.6.1. &#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;</h3>
<table>
<thead>
<tr>
<th>java&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>-</th>
<th>java&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>boolean</td>
<td>Z</td>
<td></td>
<td>long</td>
<td>J</td>
</tr>
<tr>
<td>byte</td>
<td>B</td>
<td></td>
<td>float</td>
<td>F</td>
</tr>
<tr>
<td>char</td>
<td>C</td>
<td></td>
<td>double</td>
<td>D</td>
</tr>
<tr>
<td>short</td>
<td>S</td>
<td></td>
<td>void</td>
<td>V</td>
</tr>
<tr>
<td>int</td>
<td>I</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><a name="&#x7B7E;&#x540D;&#x8BE6;&#x89E3;" class="anchor-navigation-ex-anchor" href="#&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><i class="fa fa-link" aria-hidden="true"></i></a>4.6.2. &#x7B7E;&#x540D;&#x8BE6;&#x89E3;</h3>
<pre><code class="lang-text">// &#x7C7B;&#x7684;&#x7B7E;&#x540D;&#xFF08;&#x6CE8;&#x610F;&#x672B;&#x5C3E;&#x7684;&#x5206;&#x53F7;&#xFF09;
L+&#x5305;&#x540D;+&#x7C7B;&#x540D;+&#xFF1B;
java.lang.String  -&gt;   Ljava/lang/String;

// &#x5BF9;&#x8C61;&#x7B7E;&#x540D;
&#x8DDF;&#x5B83;&#x6240;&#x5C5E;&#x7684;&#x7C7B;&#x7684;&#x7B7E;&#x540D;&#x4E00;&#x6837;&#x3002;

// &#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x7B7E;&#x540D;
&#x683C;&#x5F0F;&#xFF1A; [&#x7C7B;&#x578B;
double[ ]  -&gt;  [ D

// &#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x7B7E;&#x540D;
&#x683C;&#x5F0F;&#xFF1A;  n&#x4E2A; [   + &#x7C7B;&#x578B;&#x7B7E;&#x540D;
int[ ] [ ]   -&gt;  [[I

// &#x65B9;&#x6CD5;&#x7B7E;&#x540D;   (&#x8DDF;&#x65B9;&#x6CD5;&#x540D;&#x65E0;&#x5173;)
&#x683C;&#x5F0F;&#xFF1A; &#xFF08;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x7B7E;&#x540D;&#xFF09; + &#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x7B7E;&#x540D;
boolean fun( int a , double b , int[ ] c)   -&gt;     (ID[I)Z
void fun(int i)  -&gt; (I)V
</code></pre>
<h2 id="&#x5F15;&#x7528;&#x7C7B;&#x578B;"><a name="&#x5F15;&#x7528;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x5F15;&#x7528;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.7. &#x5F15;&#x7528;&#x7C7B;&#x578B;</h2>
<pre><code class="lang-text">//&#x5168;&#x5C40;&#x5F15;&#x7528;
&#x5168;&#x5C40;&#x5F15;&#x7528;&#x53EF;&#x4EE5;&#x8DE8;&#x65B9;&#x6CD5;&#x3001;&#x8DE8;&#x7EBF;&#x7A0B;&#x4F7F;&#x7528;&#xFF0C;&#x76F4;&#x5230;&#x88AB;&#x663E;&#x5F0F;&#x91CA;&#x653E;&#x3002;
NewGlobalRef() //&#x65B0;&#x5EFA;&#x5168;&#x5C40;&#x53D8;&#x91CF;
DeleteGlobalRef() //&#x5220;&#x9664;&#x5168;&#x5C40;&#x5F15;&#x7528;

//&#x5C40;&#x90E8;&#x5F15;&#x7528;
&#x5C40;&#x90E8;&#x5F15;&#x7528;&#x4EC5;&#x5728;&#x521B;&#x5EFA;&#x5B83;&#x7684;native&#x51FD;&#x6570;&#x53CA;&#x8BE5;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x4E2D;&#x6709;&#x6548;&#x3002;&#x5C40;&#x90E8;&#x5F15;&#x7528;&#x5C06;&#x5728;&#x8BE5;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x65F6;&#x88AB;&#x91CA;&#x653E;&#x3002;
DeleteLocalRef() //&#x5220;&#x9664;&#x5F15;&#x7528;

// &#x5F31;&#x5168;&#x5C40;&#x5F15;&#x7528;
&#x4E0E;&#x5168;&#x5C40;&#x5F15;&#x7528;&#x7C7B;&#x4F3C;&#xFF0C;&#x5F31;&#x5F15;&#x7528;&#x53EF;&#x4EE5;&#x8DE8;&#x65B9;&#x6CD5;&#x3001;&#x7EBF;&#x7A0B;&#x4F7F;&#x7528;&#x3002;&#x4F46;&#x5F31;&#x5F15;&#x7528;&#x4E0D;&#x4F1A;&#x963B;&#x6B62;GC&#x56DE;&#x6536;&#x5B83;&#x5F15;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;
&#x5B83;&#x6240;&#x5F15;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#x53EF;&#x80FD;&#x662F;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x6216;&#x8005;&#x5DF2;&#x7ECF;&#x88AB;&#x56DE;&#x6536;&#x3002;&#x5728;&#x5185;&#x5B58;&#x4E0D;&#x8DB3;&#x65F6;&#x53EF;&#x80FD;&#x4F1A;&#x88AB;&#x6536;&#x56DE;&#x4E86;&#x3002;&#x4F7F;&#x7528;&#x524D;&#x5148;&#x5224;&#x65AD;&#x4E00;&#x4E0B;&#x3002;
global_weakRef_str= (jstring) env-&gt;NewWeakGlobalRef(str2);
if(! env-&gt;IsSameObject(NULL , global_weakRef_str)){
    showLog(&quot;this global_weakRef_str is usefully&quot;) ;
}
env-&gt;DeleteWeakGlobalRef(global_weakRef_str) ;
</code></pre>
<h2 id="java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><a name="java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;" class="anchor-navigation-ex-anchor" href="#java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>4.8. Java &#x548C; C &#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;</h2>
<pre><code class="lang-text">// { java&#x4E2D;&#x51FD;&#x6570;&#x540D;&#x5B57; , &#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C; , &#x5BF9;&#x5E94;&#x7684;c&#x51FD;&#x6570;}
{
  &quot;setUsbLinkVideoData&quot;,
  &quot;(Ljava/nio/ByteBuffer;I)V&quot;,
    (void*)com_media_ffmpeg_FFMpegPlayer_setUsbLinkVideoData
}
</code></pre>
<h2 id="&#x5E38;&#x7528;&#x51FD;&#x6570;"><a name="&#x5E38;&#x7528;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>4.9. &#x5E38;&#x7528;&#x51FD;&#x6570;</h2>
<table>
<thead>
<tr>
<th>&#x51FD;&#x6570;&#x540D;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>FindClass</td>
<td></td>
</tr>
<tr>
<td>CallIntMethod</td>
<td></td>
</tr>
<tr>
<td>CallVoidMethod</td>
<td></td>
</tr>
<tr>
<td>GetStaticMethodID</td>
<td></td>
</tr>
<tr>
<td>CallStaticIntMethod</td>
<td></td>
</tr>
<tr>
<td>NewObject</td>
<td></td>
</tr>
<tr>
<td>CallStaticObjectMethod</td>
<td></td>
</tr>
<tr>
<td>NewStringUTF</td>
<td></td>
</tr>
<tr>
<td>GetStringUTFChars</td>
<td>&#x5F97;&#x5230;&#x4E00;&#x4E2A;UTF-8&#x7F16;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>GetStringChars</td>
<td>&#x5F97;&#x5230;UTF-16&#x7F16;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>ReleaseStringUTFChars</td>
<td></td>
</tr>
<tr>
<td>JNI_OnLoad</td>
<td>so&#x5E93;&#x52A0;&#x8F7D;&#x65F6;&#x8C03;&#x7528;&#x3002; <br>&#x5982;&#x679C;&#x4F60;&#x7684;*.so&#x6863;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;JNI_OnLoad()&#x51FD;&#x6570;&#xFF0C;VM&#x4F1A;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x6700;&#x8001;&#x7684;JNI 1.1&#x7248;&#x672C;&#x3002;</td>
</tr>
<tr>
<td>JNI_OnUnload</td>
<td>-</td>
</tr>
<tr>
<td>SetByteArrayRegion</td>
<td>&#x5C06;&#x672C;&#x5730;&#x7684;&#x6570;&#x7EC4;&#x6570;&#x636E;&#x62F7;&#x8D1D;&#x5230;&#x4E86; Java &#x7AEF;&#x7684;&#x6570;&#x7EC4;&#x4E2D;</td>
</tr>
<tr>
<td>env-&gt;ThrowNew</td>
<td>&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x4FE1;&#x606F; <br> jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;); <br> env-&gt;ThrowNew(exceptionClazz, &quot;&#x81EA;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&quot;);</td>
</tr>
<tr>
<td>reinterpret_cast</td>
<td>&#x7C7B;&#x578B;&#x5F3A;&#x5236;&#x8F6C;&#x6362;<br>MyParcel<em> parcel = reinterpret_cast &lt;MyParcel</em>&gt;(nativePtr);</td>
</tr>
<tr>
<td>GetStaticFieldID</td>
<td></td>
</tr>
<tr>
<td>SetStaticFieldID</td>
<td></td>
</tr>
</tbody>
</table>
<pre><code class="lang-text">GetBooleanField( )  // &#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;(&#x975E;&#x9759;&#x6001;)&#x57DF;&#x7684;&#x503C;
GetByteField( )
GetCharField( )
GetShortField( )
GetIntField( )
GetLongField( )
GetFloatField( )
GetDoubleField( )

GetObjectClass( )     // &#x6839;&#x636E; &#x5BF9;&#x8C61; &#x83B7;&#x53D6;&#x7C7B;
GetMethodID( )        //  &#x6839;&#x636E;&#x540D;&#x5B57;&#x83B7;&#x53D6;Java&#x4E2D;&#x6307;&#x5B9A;&#x7C7B;&#x7684;&#x6307;&#x5B9A;&#x51FD;&#x6570;
CallVoidMethod( )     //  &#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;void&#x7684;Java&#x51FD;&#x6570;
CallBooleanMethod ( ) // &#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;boolean&#x7684;Java&#x51FD;&#x6570;
AttachCurrentThread   //&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x83B7;&#x53D6;JNI&#x73AF;&#x5883;
DetachCurrentThread( ) //  &#x9000;&#x51FA;&#x5F53;&#x524D;JNI&#x73AF;&#x5883;

GetBooleanArrayElements( )  // &#x83B7;&#x5F97;&#x6570;&#x7EC4;&#x6307;&#x9488;
GetByteArrayElements( )  //
GetCharArrayElements( ) 
GetShortArrayElements( ) 
GetIntArrayElements( ) 
GetLongArrayElements( ) 
GetFloatArrayElements( ) 
GetDoubleArrayElements( )
</code></pre>
<h3 id="jnionload"><a name="jnionload" class="anchor-navigation-ex-anchor" href="#jnionload"><i class="fa fa-link" aria-hidden="true"></i></a>4.9.1. JNI_OnLoad(...)</h3>
<pre><code class="lang-text">JavaVM* java_vm = NULL;
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
    JNIEnv *env;
    if (vm-&gt;GetEnv(  (void**) &amp;env,  JNI_VERSION_1_4) != JNI_OK)
    {
        return JNI_ERR ;
    }
    java_vm = vm;
    return JNI_VERSION_1_4;
}
</code></pre>
<h2 id="&#x6253;&#x5370;&#x65E5;&#x5FD7;"><a name="&#x6253;&#x5370;&#x65E5;&#x5FD7;" class="anchor-navigation-ex-anchor" href="#&#x6253;&#x5370;&#x65E5;&#x5FD7;"><i class="fa fa-link" aria-hidden="true"></i></a>4.10. &#x6253;&#x5370;&#x65E5;&#x5FD7;</h2>
<pre><code class="lang-text">#include &lt;android/log.h&gt;
#define LogTag &quot;WK_LOGER&quot;
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LogTag ,__VA_ARGS__);
</code></pre>
<h2 id="&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><a name="&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><i class="fa fa-link" aria-hidden="true"></i></a>4.11. &#x5F02;&#x5E38;&#x5B9A;&#x4F4D;</h2>
<pre><code class="lang-text">// androidsudio JNI&#x5D29;&#x6E83; &#x62A5;&#x9519;&#x5B9A;&#x4F4D;&#xFF1A;
xxx \app\build\intermediates\cmake\debug\obj 
&#x8BF7;&#x8FDB;&#x5165;&#x6B63;&#x786E;&#x7684;&#x76EE;&#x5F55; , &#x8BE5;&#x76EE;&#x5F55;&#x4E0B;&#x6709;&#x5404;&#x79CD;&#x67B6;&#x6784;&#x7C7B;&#x578B;&#x7684;&#x6587;&#x4EF6;&#x5939;&#xFF0C; arm64-v8a&#x3001;armeabi-v7a&#x3001;x86_64&#x7B49;&#x3002;
&#x627E;&#x5230;&#x6709;XX.so &#x7684;&#x6587;&#x4EF6;&#x5939;&#x3002;&#x4F8B;&#x5982;&#x6211;&#x7684;&#x5C31;&#x662F; arm64-v8a &#x91CC;&#x9762;&#x6709;so&#x3002;
&#x8F93;&#x5165;&#x547D;&#x4EE4;&#xFF1A;adb shell logcat | ndk-stack -sym arm64-v8a &#x3002;
&#x4F1A;&#x63D0;&#x793A;&#x662F;&#x5177;&#x4F53;&#x54EA;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x62A5;&#x9519;&#xFF0C;&#x4E0D;&#x8FC7;&#x4ECD;&#x7136;&#x4E0D;&#x80FD;&#x50CF;Java&#x4EE3;&#x7801;&#x70B9;&#x51FB;&#x5C31;&#x4F1A;&#x8DF3;&#x8F6C;&#x7684;&#x3002;

//cmake&#x7F16;&#x8BD1;&#x9519;&#x8BEF;&#x5B9A;&#x4F4D;&#xFF1A;
&#x5F53;CMakeLists.txt &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#x9519;&#x8BEF;&#x65F6;&#xFF0C;&#x4F1A;&#x63D0;&#x793A;&#x7F16;&#x8BD1;&#x4E0D;&#x8FC7;&#xFF0C;&#x9519;&#x8BEF;&#x5B9A;&#x4F4D;&#x65B9;&#x6CD5;&#x3002;
CMake&#x7684;&#x9519;&#x8BEF;&#x8F93;&#x51FA;&#x4E0D;&#x5728;console&#x7A97;&#x53E3;&#x4E2D;&#xFF0C;&#x800C;&#x662F;&#x5728; &#x672C;&#x5DE5;&#x7A0B;&#x7684; cmake_server_log.txt&#x6587;&#x4EF6;&#x4E2D;&#x3002;
&#x6253;&#x5F00;&#x8BE5;&#x6587;&#x4EF6;&#x641C;&#x7D22;error&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5177;&#x4F53;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;
</code></pre>
<h2 id="&#x7F13;&#x5B58;&#x7B56;&#x7565;"><a name="&#x7F13;&#x5B58;&#x7B56;&#x7565;" class="anchor-navigation-ex-anchor" href="#&#x7F13;&#x5B58;&#x7B56;&#x7565;"><i class="fa fa-link" aria-hidden="true"></i></a>4.12. &#x7F13;&#x5B58;&#x7B56;&#x7565;</h2>
<p>&#x76F4;&#x63A5;&#x7528;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x4E5F;&#x53EF;&#x4EE5;&#xFF08;&#x4F46;&#x662F;&#x53EF;&#x80FD;&#x4F1A;&#x88AB;&#x5176;&#x4ED6;&#x7C7B;&#x7684;&#x7A0B;&#x5E8F;&#x4FEE;&#x6539;&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x5EFA;&#x8BAE;&#x7528;&#x9759;&#x6001;static&#x8F83;&#x5B89;&#x5168;&#x3002;</p>
<pre><code class="lang-text">Java_com_xxx_staticLocalCache(JNIEnv *env, jclass jclz, jstring name) { 
    static jfieldID j_fid = NULL;  //&#x5C40;&#x90E8;&#x7F13;&#x5B58;
    if (j_fid == NULL) {
        j_fid = (*env)-&gt;GetStaticFieldID(env, jclz, &quot;name&quot;, &quot;Ljava/lang/String;&quot;)
    }  
}

static jfieldID j_fid = NULL;// &#x5168;&#x5C40;&#x7F13;&#x5B58;
Java_com_xxx_initStaticCache  (JNIEnv *env, jclass jclz){
    j_fid = (*env)-&gt;GetStaticFieldID(env, jclz, &quot;name&quot;, &quot;Ljava/lang/String;&quot;);
}
// &#x8FD9;&#x4E5F;&#x53EB;&#x7F13;&#x5B58;&#xFF1F;&#x4E71;&#x4E03;&#x516B;&#x7CDF;&#x3002;
</code></pre>
<h2 id="java&#x8C03;&#x7528;native"><a name="java&#x8C03;&#x7528;native" class="anchor-navigation-ex-anchor" href="#java&#x8C03;&#x7528;native"><i class="fa fa-link" aria-hidden="true"></i></a>4.13. java&#x8C03;&#x7528;native</h2>
<p>&#x6CE8;&#x610F;&#x6587;&#x4EF6;&#x5939;&#x8DEF;&#x5F84;&#x8981;&#x548C;native&#x4E2D;&#x7684;&#x7B7E;&#x540D;&#x4E00;&#x6837;</p>
<pre><code class="lang-text">static {
    System.loadLibrary(&quot;music-player&quot;);
}
private native void nPlay(String url);
</code></pre>
<h2 id="native-&#x8C03;&#x7528;-java"><a name="native-&#x8C03;&#x7528;-java" class="anchor-navigation-ex-anchor" href="#native-&#x8C03;&#x7528;-java"><i class="fa fa-link" aria-hidden="true"></i></a>4.14. native &#x8C03;&#x7528; java</h2>
<h3 id="c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><a name="c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>4.14.1. C++&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-text">1&#x3001;&#x6839;&#x636E;jobject&#x83B7;&#x53D6;jclass
 jclass jlz = env-&gt;GetObjectClass(instance);//jobject instance
2&#x3001;&#x83B7;&#x53D6; jmethodID
jmethodID jmid_error= jniEnv-&gt;GetMethodID(jlz, &quot;onError&quot;, &quot;(ILjava/lang/String;)V&quot;);
3&#x3001;&#x8C03;&#x7528;&#x65B9;&#x6CD5;
jniEnv-&gt;CallVoidMethod(jobj, jmid_error, code, jmsg);// jobject,jmethodID , &#x53C2;&#x6570;...
</code></pre>
<h3 id="c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><a name="c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>4.14.2. C++&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-text">JniEnv&#x662F;&#x7EBF;&#x7A0B;&#x76F8;&#x5173;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x7684;JniEnv&#xFF1B;
JVM&#x662F;&#x8FDB;&#x7A0B;&#x76F8;&#x5173;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;JVM&#x6765;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;JniEnv&#xFF0C;&#x7136;&#x540E;&#x624D;&#x80FD;&#x8C03;&#x7528;Java&#x7684;&#x65B9;&#x6CD5;&#x3002;

JNIEnv *jniEnv;
if (javaVM-&gt;AttachCurrentThread(&amp;jniEnv, 0) != JNI_OK)
{
    return;
}
// &#x5982;&#x679C;&#x83B7;&#x53D6;&#x6210;&#x529F;&#xFF0C;AttachCurrentThread &#x5C31;&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5C5E;&#x4E8E;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;JNIEnv&#x6307;&#x9488;&#x3002;
jniEnv-&gt;CallVoidMethod(...);
//&#x6267;&#x884C;&#x76F8;&#x5173;&#x64CD;&#x4F5C;...
javaVM-&gt;DetachCurrentThread();
</code></pre>
<h2 id="posix&#x7EBF;&#x7A0B;"><a name="posix&#x7EBF;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#posix&#x7EBF;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.15. POSIX&#x7EBF;&#x7A0B;</h2>
<p>Android NDK&#x7684;&#x7EBF;&#x7A0B;&#x662F;&#x901A;&#x8FC7;POSIX&#x6807;&#x51C6;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4E5F;&#x53EB;POSIX&#x7EBF;&#x7A0B;&#x3002;</p>
<h3 id="posix-&#x4F7F;&#x7528;"><a name="posix-&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#posix-&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>4.15.1. POSIX &#x4F7F;&#x7528;</h3>
<pre><code class="lang-text">//&#x5934;&#x6587;&#x4EF6;
#include &lt;pthread.h&gt;
// &#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x9501;&#x5BF9;&#x8C61;
pthread_mutex_t mutex;
// &#x7528;&#x6765;&#x7533;&#x660E;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x5BF9;&#x8C61;
pthread_t thread
//&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;
pthread_cond_t cond; 
pthread_attr_t&#xFF1A;&#x7EBF;&#x7A0B;&#x5C5E;&#x6027;
Thread-local storage&#xFF08;&#x6216;&#x8005;&#x4EE5;Pthreads&#x672F;&#x8BED;&#xFF0C;&#x79F0;&#x4F5C;&#x7EBF;&#x7A0B;&#x7279;&#x6709;&#x6570;&#x636E;&#xFF09;&#xFF1A;
</code></pre>
<h3 id="posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><a name="posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>4.15.2. POSIX &#x5E38;&#x7528;&#x65B9;&#x6CD5;</h3>
<table>
<thead>
<tr>
<th>&#x5E38;&#x7528;&#x65B9;&#x6CD5;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>pthread_create(...)</td>
<td>&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;. <br>pthread_create(&amp;playThreadT, NULL, threadPlay, this);<br>&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8FD0;&#x884C;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</td>
</tr>
<tr>
<td>pthread_detach()</td>
<td>&#x5373;&#x4E3B;&#x7EBF;&#x7A0B;&#x4E0E;&#x5B50;&#x7EBF;&#x7A0B;&#x5206;&#x79BB;&#xFF0C;&#x5B50;&#x7EBF;&#x7A0B;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x5B50;&#x7EBF;&#x7A0B;&#x8D44;&#x6E90;&#x81EA;&#x52A8;&#x56DE;&#x6536;</td>
</tr>
<tr>
<td>pthread_exit()</td>
<td>&#x7EC8;&#x6B62;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;</td>
</tr>
<tr>
<td>pthread_join()</td>
<td>&#x963B;&#x585E;&#x5F53;&#x524D;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x76F4;&#x5230;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;&#x7ED3;&#x675F;</td>
</tr>
<tr>
<td>pthread_attr_init()</td>
<td>&#x521D;&#x59CB;&#x5316;&#x7EBF;&#x7A0B;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_attr_setdetachstate()</td>
<td>&#x51B3;&#x5B9A;&#x8FD9;&#x4E2A;&#x7EBF;&#x7A0B;&#x5728;&#x7EC8;&#x6B62;&#x65F6;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x88AB;&#x7ED3;&#x5408;</td>
</tr>
<tr>
<td>pthread_attr_getdetachstate()</td>
<td>&#x83B7;&#x53D6;&#x8131;&#x79BB;&#x72B6;&#x6001;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_attr_destroy()</td>
<td>&#x5220;&#x9664;&#x7EBF;&#x7A0B;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_kill()</td>
<td>&#x5411;&#x7EBF;&#x7A0B;&#x53D1;&#x9001;&#x4E00;&#x4E2A;&#x4FE1;&#x53F7;</td>
</tr>
<tr>
<td>pthread_mutex_init(...)</td>
<td>&#x521D;&#x59CB;&#x5316;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_destroy(...)</td>
<td>&#x5220;&#x9664;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_lock(...)</td>
<td>&#x5360;&#x6709;&#x4E92;&#x65A5;&#x9501;&#xFF08;&#x963B;&#x585E;&#x64CD;&#x4F5C;&#xFF09;</td>
</tr>
<tr>
<td>pthread_mutex_trylock()</td>
<td>&#x8BD5;&#x56FE;&#x5360;&#x6709;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_unlock()</td>
<td>&#x91CA;&#x653E;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_cond_init(...)</td>
<td>&#x521D;&#x59CB;&#x5316;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;</td>
</tr>
<tr>
<td>pthread_cond_destroy(...)</td>
<td>&#x9500;&#x6BC1;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;</td>
</tr>
<tr>
<td>pthread_cond_signal(...)</td>
<td>&#x53D1;&#x51FA;&#x6761;&#x4EF6;&#x4FE1;&#x53F7;&#xFF0C;<br>&#x5524;&#x9192;&#x7B2C;&#x4E00;&#x4E2A;&#x8C03;&#x7528;pthread_cond_wait()&#x800C;&#x8FDB;&#x5165;&#x7761;&#x7720;&#x7684;&#x7EBF;&#x7A0B;</td>
</tr>
<tr>
<td>pthread_cond_wait()</td>
<td>&#x7528;&#x4E8E;&#x7EBF;&#x7A0B;&#x963B;&#x585E;&#x7B49;&#x5F85;&#xFF0C;&#x76F4;&#x5230; pthread_cond_signal &#x53D1;&#x51FA;&#x6761;&#x4EF6;&#x4FE1;&#x53F7;&#x540E;&#x624D;&#x6267;&#x884C;&#x540E;&#x7EED;&#x64CD;&#x4F5C;</td>
</tr>
<tr>
<td>pthread_key_create()</td>
<td>&#x5206;&#x914D;&#x7528;&#x4E8E;&#x6807;&#x8BC6;&#x8FDB;&#x7A0B;&#x4E2D;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x7684;&#x952E;</td>
</tr>
<tr>
<td>pthread_setspecific()</td>
<td>&#x4E3A;&#x6307;&#x5B9A;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x952E;&#x8BBE;&#x7F6E;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x7ED1;&#x5B9A;</td>
</tr>
<tr>
<td>pthread_getspecific()</td>
<td>&#x83B7;&#x53D6;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x7684;&#x952E;&#x7ED1;&#x5B9A;&#xFF0C;&#x5E76;&#x5C06;&#x8BE5;&#x7ED1;&#x5B9A;&#x5B58;&#x50A8;&#x5728; value &#x6307;&#x5411;&#x7684;&#x4F4D;&#x7F6E;&#x4E2D;</td>
</tr>
<tr>
<td>pthread_key_delete()</td>
<td>&#x9500;&#x6BC1;&#x73B0;&#x6709;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x952E;</td>
</tr>
<tr>
<td>pthread_attr_getschedparam()</td>
<td>&#x83B7;&#x53D6;&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;</td>
</tr>
<tr>
<td>pthread_attr_setschedparam()</td>
<td>&#x8BBE;&#x7F6E;&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;</td>
</tr>
<tr>
<td>pthread_equal()</td>
<td>&#x5BF9;&#x4E24;&#x4E2A;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x6807;&#x8BC6;&#x53F7;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;</td>
</tr>
<tr>
<td>pthread_self()</td>
<td>&#x67E5;&#x8BE2;&#x7EBF;&#x7A0B;&#x81EA;&#x8EAB;&#x7EBF;&#x7A0B;&#x6807;&#x8BC6;&#x53F7;</td>
</tr>
<tr>
<td>pthread_cancel()</td>
<td>&#x5728;&#x5B89;&#x5353;NDK&#x4E2D;&#x5DF2;&#x7ECF;&#x88AB;&#x5220;&#x9664;&#x3002;&#x56E0;&#x4E3A;&#x6BD4;&#x8F83;&#x5371;&#x9669;&#x3002;</td>
</tr>
</tbody>
</table>
<h4 id="pthreadcreate"><a name="pthreadcreate" class="anchor-navigation-ex-anchor" href="#pthreadcreate"><i class="fa fa-link" aria-hidden="true"></i></a>pthread_create(...)</h4>
<pre><code class="lang-text">pthread_create(&amp;pthread,NULL,threadCallBack,NULL);
&#x5176;&#x603B;&#x5171;&#x63A5;&#x6536;4&#x4E2A;&#x53C2;&#x6570;&#xFF0C;
&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;pthread_t&#x5BF9;&#x8C61;&#xFF0C;
&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x7EBF;&#x7A0B;&#x7684;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4F20;NULL&#x5C31;&#x884C;&#xFF0C;
&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#xFF0C;
&#x7B2C;&#x56DB;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4F20;&#x9012;&#x7ED9;&#x7EBF;&#x7A0B;&#x7684;&#x53C2;&#x6570;
</code></pre>
<p><br></p>
<h4 id="pthreadexit"><a name="pthreadexit" class="anchor-navigation-ex-anchor" href="#pthreadexit"><i class="fa fa-link" aria-hidden="true"></i></a>pthread_exit(...)</h4>
<pre><code class="lang-text">pthread_exit(&amp;thread) ;
&#x53C2;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x4F20;NULL&#x3002;
</code></pre>
<h2 id="java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><a name="java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;" class="anchor-navigation-ex-anchor" href="#java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><i class="fa fa-link" aria-hidden="true"></i></a>4.16. java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;</h2>
<p>&#x5927;&#x6982;&#x539F;&#x7406;&#xFF0C;&#x5728;native&#x5F00;&#x8F9F;&#x4E00;&#x5757;&#x5185;&#x5B58;&#x3002;&#x5C06;&#x8FD9;&#x5757;&#x5185;&#x5B58;&#x7684;&#x9996;&#x5730;&#x5740;&#x4F20;&#x7ED9;java&#x5C42;&#xFF0C;&#x4EE5;&#x540E;&#x7684;&#x76F8;&#x5173;&#x64CD;&#x4F5C;&#x5C31;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x5730;&#x5740;&#x83B7;&#x5F97;&#x8FD9;&#x5757;&#x5185;&#x5B58;&#xFF0C;&#x7528;native&#x4EE3;&#x7801;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;&#x5185;&#x5B58;&#x3002;</p>
<pre><code class="lang-text">&#x6682;&#x65F6;&#x7528;&#x5F97;&#x5C11;&#xFF0C;&#x4EE5;&#x540E;&#x518D;&#x8865;&#x5145;&#x3002;
android&#x4E2D;&#x7684;&#x5E94;&#x7528;&#x6709; Parcel&#xFF0C;&#x56E0;&#x4E3A;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;&#x5185;&#x5B58;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6BD4;&#x64CD;&#x4F5C;IO&#x7684;Serializable &#x6548;&#x7387;&#x9AD8;&#x3002;
</code></pre>
<h2 id="&#x5176;&#x4ED6;_1"><a name="&#x5176;&#x4ED6;_1" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;_1"><i class="fa fa-link" aria-hidden="true"></i></a>4.17. &#x5176;&#x4ED6;</h2>
<pre><code class="lang-text">RegisterNatives(clazz, methods, size)   // &#x5C06;clazz&#x7C7B;&#x4E2D;&#x7684; &#x6240;&#x6709;&#x65B9;&#x6CD5;methods&#x5168;&#x90E8;&#x6CE8;&#x518C;&#x4E3A;&#x672C;&#x5730;&#x65B9;&#x6CD5;&#x3002;
jlong id= reinterpret_cast&lt;jlong&gt;(record);  // c++ &#x5BF9;&#x8C61;&#x4E0E;&#x5BF9;&#x8C61;&#x53E5;&#x67C4;&#x8FDB;&#x884C;&#x4E92;&#x76F8;&#x8F6C;&#x6362;
auto *record = reinterpret_cast&lt;CameraRecord *&gt;(id);
</code></pre>
<h2 id="jni-demo"><a name="jni-demo" class="anchor-navigation-ex-anchor" href="#jni-demo"><i class="fa fa-link" aria-hidden="true"></i></a>4.18. jni Demo</h2>
<p><a href="https://gitee.com/AivinPrivate/Android_Jni_cpp" target="_blank">jniSample</a> &#x6F14;&#x793A;&#x6548;&#x679C;&#xFF1A;</p>
<ul>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> java&#x8C03;&#x7528;c++</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> c++&#x56DE;&#x8C03;Java&#x51FD;&#x6570;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> c++&#x83B7;&#x53D6;&#x5E76;&#x4FEE;&#x6539;Java&#x9759;&#x6001;&#x53D8;&#x91CF;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> Java&#x5F00;&#x542F;&#x5B50;&#x7EBF;&#x7A0B;&#x8BA9;c++&#x6267;&#x884C;&#x8017;&#x65F6;&#x64CD;&#x4F5C;&#xFF0C;&#x5E76;&#x66F4;&#x65B0;Java ui</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> &#x4F20;&#x9012;&#x5E76;&#x4FEE;&#x6539;&#x6570;&#x7EC4;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> c++&#x521B;&#x5EFA;Java&#x5B9A;&#x4E49;&#x7684;&#x5BF9;&#x8C61;&#x5E76;&#x8FD4;&#x56DE;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled"> c++&#x8C03;&#x7528;&#x7B2C;&#x4E09;&#x65B9;&#x5E93;&#x5B9E;&#x73B0;&#x52A0;&#x5BC6;&#x89E3;&#x5BC6;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled"> c++&#x8BFB;&#x53D6;&#x6587;&#x4EF6;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled"> c++&#x63A5;&#x6536;Java&#x4F20;&#x9012;&#x7684;&#x63A7;&#x4EF6; &#x5E76;&#x7ED8;&#x5236;&#x56FE;&#x50CF;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> c++&#x83B7;&#x53D6;apk&#x5305;&#x540D;</li>
<li style="list-style: none"><input type="checkbox" disabled="disabled" checked="checked"> c++&#x83B7;&#x53D6;apk&#x7B7E;&#x540D; &#x54C8;&#x5E0C;&#x503C; (&#x7B7E;&#x540D;&#x6821;&#x9A8C;)</li>
</ul>
<h2 id="jni&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;"><a name="jni&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;" class="anchor-navigation-ex-anchor" href="#jni&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;"><i class="fa fa-link" aria-hidden="true"></i></a>4.19. JNI&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x751F;&#x6210;&#x5DE5;&#x5177;</h2>
<pre><code class="lang-text">public class SignatureGen
{
    private  static final HashMap&lt;String,String&gt; Primitives = new HashMap&lt;String, String&gt;();

    static
    {
        Primitives.put(Void.class.getName(),&quot;V&quot;);
        Primitives.put(Boolean.class.getName(),&quot;Z&quot;);
        Primitives.put(Byte.class.getName(),&quot;B&quot;);
        Primitives.put(Character.class.getName(),&quot;C&quot;);
        Primitives.put(Short.class.getName(),&quot;S&quot;);
        Primitives.put(Integer.class.getName(),&quot;I&quot;);
        Primitives.put(Long.class.getName(),&quot;J&quot;);
        Primitives.put(Float.class.getName(),&quot;F&quot;);
        Primitives.put(Double.class.getName(),&quot;D&quot;);                
    }

    /**
     * @param &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x7C7B;&#x578B;
     * @param params &#x53C2;&#x6570;&#x7C7B;&#x578B;
     * @return &#x7B7E;&#x540D;
     */
    public static String getSignature( Class ret, Class...params )
    {
        StringBuilder builder = new StringBuilder();
        builder.append(&quot;(&quot;);
        for( Class param : params ) {
            builder.append(getSignature(param));
        }        
        builder.append(&quot;)&quot;);
        builder.append(getSignature(ret));
        return builder.toString();
    }

    private static String getSignature( Class  param )
    {
        StringBuilder builder = new StringBuilder();
        String name = &quot;&quot;;
        if( param.isArray() )
        {
            name = param.getComponentType().getName();
            builder.append(&quot;[&quot;);
        }else {
            name = param.getName();                
        }

        if( Primitives.containsKey(name) )
        {
            builder.append(Primitives.get(name));
        }
        else {            
            builder.append(&quot;L&quot;+name.replace(&quot;.&quot;,&quot;/&quot;)+&quot;;&quot;);
        }

        return builder.toString();
    }

}

//&#x4F7F;&#x7528;&#x65B9;&#x6CD5;
//&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B; &#xFF0C;&#x540E;&#x9762;&#x7684;&#x53C2;&#x6570;&#x662F;&#x53C2;&#x6570;&#x7C7B;&#x578B;
&#x4F8B;&#x5982;&#x9700;&#x8981;&#x83B7;&#x5F97;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x7B7E;&#x540D;&#xFF1A;
int func(boolean a,String b)
//&#x53C2;&#x6570;&#x5E94;&#x8BE5;&#x8FD9;&#x6837;&#x586B;&#x5199;
SignatureGen.getSignature(Integer.class,Boolean.class,String.class));
//&#x83B7;&#x5F97;&#x7B7E;&#x540D;&#x5982;&#x4E0B;
(ZLjava/lang/String;)I
</code></pre>
<h2 id="posix-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><a name="posix-&#x7B80;&#x5355;&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#posix-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.20. POSIX &#x7B80;&#x5355;&#x793A;&#x4F8B;</h2>
<pre><code class="lang-text">#include &lt;jni.h&gt;
#include &quot;wkplayer.h&quot;
#include &lt;pthread.h&gt;
#include &lt;unistd.h&gt;
JavaVM* java_vm = NULL;
pthread_mutex_t mutex;
// &#x5168;&#x5C40; &#x56DE;&#x8C03;&#x5BF9;&#x8C61;
jobject callback = NULL;
// &#x5168;&#x5C40;&#x56DE;&#x8C03;&#x51FD;&#x6570;
jmethodID gOnNativeMessage = NULL;

//&#x4F20;&#x9012;pthread&#x53C2;&#x6570;&#x7528;&#x7684;&#x7ED3;&#x6784;&#x4F53;
struct NativeWorkerArgs
{
    jint id;
    char  reslut[20];
};

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_FFmpegPlayer_playMyMedia(JNIEnv *env, jobject instance, jstring url_)
{
    const char *url = env-&gt;GetStringUTFChars(  url_, 0);
    LOGI(&quot;url:%s&quot;, url);
    env-&gt;ReleaseStringUTFChars( url_, url);
    // &#x5728;&#x903B;&#x8F91;&#x9700;&#x8981;&#x7684;&#x65F6;&#x5019;&#x5F00;&#x542F;&#x5B50;&#x7EBF;&#x7A0B;&#xFF0C;&#x5E76;&#x5728;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x56DE;&#x8C03;java&#x51FD;&#x6570;
    pthread_t  handle ;
    //&#x4F20;&#x5230;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;&#x53C2;&#x6570;
    NativeWorkerArgs* nativeWorkArgs = new NativeWorkerArgs();
    nativeWorkArgs-&gt;id = 100;
    strcpy(nativeWorkArgs-&gt;reslut , &quot;&#x767B;&#x5F55;&#x6210;&#x529F;&#xFF01;&quot;);
    //&#x521B;&#x5EFA;&#x7EBF;&#x7A0B; 0 &#x4EE3;&#x8868;&#x6210;&#x529F;
    int result = pthread_create(&amp;handle, NULL, nativeWorkerThread, (void*) nativeWorkArgs);
}

//&#x5B50;&#x7EBF;&#x7A0B; &#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;
void* nativeWorkerThread(void* args)
{
    JNIEnv* env = NULL;

    if ( 0 == java_vm-&gt;AttachCurrentThread(&amp;env, NULL))
    {
        //lock
        if (0 != pthread_mutex_lock(&amp;mutex))
        {
            jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
            env-&gt;ThrowNew(exceptionClazz, &quot;Unable to lock mutex--&quot;);
        }
        NativeWorkerArgs* nativeWorkerAgrs = (NativeWorkerArgs*) args;
        // &#x6A21;&#x62DF;&#x5EF6;&#x65F6; &#xFF0C;3&#x79D2;
        sleep(2);
        LOGI(&quot;&#x53C2;&#x6570;=== %d , %s  &quot; ,nativeWorkerAgrs-&gt;id ,nativeWorkerAgrs-&gt;reslut);
        env-&gt;CallVoidMethod(  callback, gOnNativeMessage, nativeWorkerAgrs-&gt;id , env-&gt;NewStringUTF(nativeWorkerAgrs-&gt;reslut)   );
        delete nativeWorkerAgrs;
        java_vm-&gt;DetachCurrentThread();

        if (0 != pthread_mutex_unlock(&amp;mutex))
        {
            jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
            env-&gt;ThrowNew(exceptionClazz, &quot;Unable to unlock mutex--&quot;);
        }
    }
    return NULL;
}

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_FFmpegPlayer_setNativeCallback(JNIEnv *env,
                                                                        jobject instance,
                                                                        jobject callback0)
{

    if (NULL == callback)
    {
        callback = env-&gt;NewGlobalRef(callback0);
    }

    //&#x521D;&#x59CB;java&#x56DE;&#x8C03;
    if (NULL == gOnNativeMessage)
    {
        jclass clazz = env-&gt;GetObjectClass(callback);
        gOnNativeMessage = env-&gt;GetMethodID(clazz, &quot;callbackForNative&quot;, &quot;(ILjava/lang/String;)V&quot;);
    }

  }

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_FFmpegPlayer_initNative(JNIEnv *env, jobject instance)
{
    //&#x521D;&#x59CB;&#x5316;&#x4E92;&#x65A5;&#x91CF;
    if (0 != pthread_mutex_init(&amp;mutex, NULL))
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;Unable to init mutex&quot;);
    }

}

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_FFmpegPlayer_freeNative(JNIEnv *env, jobject instance)
{
    if (NULL != callback)
    {
        env-&gt;DeleteGlobalRef(callback);
        callback = NULL;
    }

    //&#x91CA;&#x653E;&#x4E92;&#x65A5;&#x91CF;
    if (0 != pthread_mutex_destroy(&amp;mutex))
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;Unable to destroy mutex--&quot;);
    }

}
</code></pre>
<h2 id="tcp-socket-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><a name="tcp-socket-&#x7B80;&#x5355;&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#tcp-socket-&#x7B80;&#x5355;&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.21. TCP socket &#x7B80;&#x5355;&#x793A;&#x4F8B;</h2>
<p>&#x8BB0;&#x5F97;&#x5728;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x8FDB;&#x7A0B;&#x7F51;&#x7EDC;&#x8017;&#x65F6;&#x64CD;&#x4F5C;&#x3002;
<del>&#x7528; ByteBuffer &#x65B9;&#x5F0F;&#x6D4B;&#x8BD5;&#x5931;&#x8D25;&#x3002;&#x8FD8;&#x6CA1;&#x627E;&#x5230;&#x539F;&#x56E0;&#x3002;</del></p>
<pre><code class="lang-text">// java&#x7AEF;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;
public native boolean createSocket();
public native boolean connectSocket(String ip, int port);
public native int recvSocket(byte[] buffer, int offset, int count);
public native boolean sendStringData(String sendData);
public native boolean sendBytesData(byte[] byteBuffer);
public native boolean closeSocket();
</code></pre>
<p><br></p>
<pre><code class="lang-text">#include &lt;jni.h&gt;
#include&lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;

JavaVM* java_vm = NULL;
int sockId;
// &#x521B;&#x5EFA;socket
extern &quot;C&quot;
JNIEXPORT jboolean JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_createSocket(JNIEnv *env, jobject instance)
{
    sockId = socket(AF_INET, SOCK_STREAM, 0) ;
    if(sockId&lt;0)
    {
        return JNI_FALSE;
    }else{
        return JNI_TRUE;
    }
}

// &#x8FDE;&#x63A5; socket
extern &quot;C&quot;
JNIEXPORT jboolean JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_connectSocket(JNIEnv *env, jobject instance,
                                                                 jstring ip_, jint port)
{
    const char *ip =env -&gt;GetStringUTFChars(  ip_, 0);
    struct sockaddr_in servaddr;
    memset(&amp;servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(port);

    if (inet_pton(AF_INET, ip, &amp;servaddr.sin_addr) &lt;= 0) {
        return JNI_FALSE;
    }
    if (connect(sockId, (struct sockaddr *) &amp;servaddr, sizeof(servaddr)) &lt; 0) {
        return JNI_FALSE;
    }
    env-&gt;ReleaseStringUTFChars(   ip_, ip);
    return JNI_TRUE;

}

// &#x53D1;&#x9001; String &#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;
// &#x53D1;&#x9001;&#x4E2D;&#x6587; &#x4F1A;&#x6709;&#x4E71;&#x7801; &#x3002;
extern &quot;C&quot;
JNIEXPORT jboolean JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_sendStringData(JNIEnv *env, jobject instance,
                                                              jstring sendData_) {
    const char *sendData = env-&gt;GetStringUTFChars(   sendData_, 0);
    if (!sockId)
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;socket&#x5DF2;&#x7ECF;&#x65AD;&#x5F00;&quot;);
        return JNI_FALSE;
    }
    //LOGI(&quot;&#x53D1;&#x9001;%s=&quot; ,sendData);
    fgets((char *) sendData, 1024, stdin);
    if (send(sockId, sendData, strlen(sendData), 0) &lt; 0) {
        return JNI_FALSE;
    }
    env-&gt;ReleaseStringUTFChars(   sendData_, sendData);
    return JNI_TRUE;
}

// &#x53D1;&#x9001; byte[] &#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;
extern &quot;C&quot;
JNIEXPORT jboolean JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_sendBytesData(JNIEnv *env, jobject instance,
                                                                 jbyteArray byteBuffer_) {
    if (!sockId)
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;socket&#x5DF2;&#x7ECF;&#x65AD;&#x5F00;&quot;);
        return JNI_FALSE;
    }

    jbyte* pBuffer =   env-&gt; GetByteArrayElements(byteBuffer_ , NULL);
    jint legth = env-&gt;GetArrayLength(byteBuffer_) ;

    if (send(sockId, pBuffer, legth  , 0) &lt; 0)
    {
        return JNI_FALSE;
    }
    env-&gt;ReleaseByteArrayElements(byteBuffer_, pBuffer, 0);
    return  JNI_TRUE ;
}

// &#x63A5;&#x6536;byte[]&#x4FE1;&#x606F;
extern &quot;C&quot;
JNIEXPORT jint JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_recvSocket(JNIEnv *env, jobject instance,
                                                              jbyteArray buffer_, jint offset,
                                                              jint count) {

    if (!sockId)
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;socket&#x5DF2;&#x7ECF;&#x65AD;&#x5F00;&quot;);
        return 0;
    }
    jbyte buf[count - offset];
    int rec_len;
    if ((rec_len = (int) recv(sockId, buf, sizeof(buf), 0)) == -1)
    {
        jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;);
        env-&gt;ThrowNew(exceptionClazz, &quot;native&#x63A5;&#x6536;&#x5F02;&#x5E38;&quot;);
        return 0;
    }

    buf[rec_len] = &apos;\0&apos;;
    // &#x5C06;&#x672C;&#x5730;&#x6570;&#x636E;&#x62F7;&#x8D1D;&#x5230;java&#x7AEF;&#x7684;&#x6570;&#x7EC4;&#x4E2D;
    env-&gt;SetByteArrayRegion( buffer_, offset, count, buf);
    env-&gt;DeleteLocalRef(buffer_);
    return rec_len;

}

// &#x5173;&#x95ED;&#x8FDE;&#x63A5;
extern &quot;C&quot;
JNIEXPORT jboolean JNICALL
Java_com_walkera_cn_ffmpegforandoriddemo_TcpClinet_closeSocket(JNIEnv *env, jobject instance)
{
    int reslut = close(sockId);
    // &#x8FD4;&#x56DE;0 &#xFF0C;&#x5173;&#x95ED;&#x6210;&#x529F;
    return JNI_TRUE;

}

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv *env;
    if (vm-&gt;GetEnv(  (void**) &amp;env,  JNI_VERSION_1_4) != JNI_OK)
    {
        return JNI_ERR ;
    }
    java_vm = vm;
    return JNI_VERSION_1_4;
}
</code></pre>
<footer class="page-footer"><span class="copyright">( no Copyright&#xFF0C;enjoy youself ! ) all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">The file was updated at :
2022-04-04 10:49:02
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ccpp.html" class="navigation navigation-prev " aria-label="Previous page: cCpp">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="系统编译剪裁.html" class="navigation navigation-next " aria-label="Next page: 系统编译剪裁">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"NDK","level":"1.17.3","depth":2,"next":{"title":"系统编译剪裁","level":"1.17.4","depth":2,"path":"chinese/native/系统编译剪裁.md","ref":"chinese/native/系统编译剪裁.md","articles":[]},"previous":{"title":"cCpp","level":"1.17.2","depth":2,"path":"chinese/native/ccpp.md","ref":"chinese/native/ccpp.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","local-video","splitter","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"( no Copyright，enjoy youself ! )","modify_label":"The file was updated at :","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/native/NDK.md","mtime":"2022-04-04T02:49:02.768Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-04T03:47:09.782Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

